|
| 28 Oct 2016 03:06 AM |
In the Roblox Wiki leaderboard tutorial
tutorial page -> http://wiki.roblox.com/index.php?title=Leaderboard _____________________________________________________________________________________________ _____________________________________________________________________________________________
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local money = Instance.new("IntValue") money.Name = "Money" money.Value = 0 money.Parent = leaderstats end) while wait(5) do for _, player in ipairs(game.Players:GetPlayers()) do if player:FindFirstChild("leaderstats") then player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1 end end end
--{Here is the more standardized leaderboard example. It inserts the leaderstat model into the player, inserts the intvalue money into the leaderstats, and below it has the in pairs loop to add to every player a value of 1 to the money intvalue for every wait(5)}-- _____________________________________________________________________________________________ _____________________________________________________________________________________________
--A table for holding all the player's leaderstat values local playerLeaderstats = {} game.Players.PlayerAdded:connect(function(player) playerLeaderstats[player] = {} playerLeaderstats[player]["Money"] = 0 local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local money = Instance.new("IntValue") money.Name = "Money" money.Value = playerLeaderstats[player]["Money"] money.Parent = leaderstats end) while wait(5) do for _, player in pairs(game.Players:GetPlayers()) do --We don't use the IntValue's value because an exploiter can modify it. playerLeaderstats[player]["Money"] = playerLeaderstats[player]["Money"] + 1 if player:FindFirstChild("leaderstats") then player.leaderstats.Money.Value = playerLeaderstats[player]["Money"] end end end
--{Here's the same script, except it's built a table along with the leaderboard and increments the intvalue from the table instead of a direct value as kind of an extra check step to circumvent manipulation of the direct value, although it says that you can Workspace.FilteringEnabled set to true.}-- _____________________________________________________________________________________________ _____________________________________________________________________________________________
So the only thing I'm having trouble with is the leaderboard built to a table.
Please give me a working example of how I can make a brick that when touched, adds +1 to the "Money" IntValue using the leaderboard.
I tried quite a few different variations of what I thought should work but didnt. Sorry for such a basic question, but I'm doing my best :p
|
|
|
| Report Abuse |
|
|
|
| 28 Oct 2016 03:11 AM |
| "Please give me a working example of how I can make a brick that when touched, adds +1 to the "Money" IntValue using the leaderboard THAT USES THE TABLE****" |
|
|
| Report Abuse |
|
|
| |
|
|
| 28 Oct 2016 05:22 AM |
ServerScriptService - > Script ________________________________________________________________________________________ game.Players.PlayerAdded:connect(function(player) local event = Instance.new("RemoteEvent") event.Parent = player event.Name = "MyClientEvent" wait(1) pointPart = game.Workspace.PointPart local function fireClient() event:FireClient(player) end pointPart.Touched:connect(fireClient)
end) _______________________________________________________________________________________ _______________________________________________________________________________________ StarterPlayer -> StarterPlayerScripts -> LocalScript _______________________________________________________________________________________ local player = game.Players.Player1 game.Players.LocalPlayer:WaitForChild("MyClientEvent").OnClientEvent:connect(function() player.leaderstats.Points.Value = playerLeaderstats.Points.Value + 1 end) ______________________________________________________________________________________ ______________________________________________________________________________________
Okay, so somehow I've managed to get a client event to activate a serverscript. In this case, it will add 1 point to the points intvalue of the leaderstats leaderboard. But in the localscript, I've had to specify local player = game.Players.Player1
In that instance, what would be an easy way to obtain the directory "Player1" regardless of whether they are player1,player2,player3,etc without manually putting that in?
Also, regarding the first post, how would I define "playerLeaderstats" like...
playerLeaderstats[player]["Points"] = playerLeaderstats[player]["Points"] + 500000 ^^^^^^^^^^^^^^^^^ if I were to try and use this from the table that was created. When referenced outside of the serverscript that this table was created in, it brings up a nil value. How would I recall that table?
|
|
|
| Report Abuse |
|
|
| |
|