There is my script to make the leaderboard:
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local money = Instance.new("IntValue") --We create a new IntValue money.Name = "Money" --this is the name you want the leader-stat to be when it shows up in-game. --this is the value of money the new player starts out with. To change this, you can add some more code (shown later) money.Parent = leaderstats -- Set the money object as a child of the leaderstats object. end)
and there is my script to add point to leaderboard:
while true do wait(1) game.Players.LocalPlayer.leaderstats.Money.Value = 1 end
Why my money stay to 0?
if the code that listens for when a player enters a server is in a local script, then it won't make the leaderboard at all;
and also, if the code that is suppose to increase/decrease the amount is in local script then, you the amount will only increase on player's screen...
so make you sure you use server scripts on both;
exampe:
in server script
game.Players.PlayerAdded:Connect(function(player) local stat = instance.new("Folder", player) -- makes new folder and puts it in player object' stat.Name = "leaderstats" local money = instance.new("IntValue",stat) money.Name = "Money" Money.Value = 0 end)
in another server script; even tho you can technically use same script, but make sure the following code is below the above code, if your using same script
wait(5) -- to make sure it doesn't run immediately after server startup local cashPerSecond = 20 while wait(1) do for _, player in pairs(game.Players:GetPlayers()) do local stat = player:WaitForChild("leaderstats") local money = stat:WaitForChild("Money") money.Value = money.Value + cashPerSecond end end
u cannot do that but u can
local function setVal(val,newVal) local x = Instance.new(val.ClassName, val.Parent) x.Name = val.Name val:Destroy() x.Value = newVal end setVal(money,1)
You have to make it in the same script like this put this in the same script
while true do wait(1)--- change to how long it must take to get the money money.Value = money.Value +1 --- change "+1" to how much money you get (don't touch the plus unless you want it to - the stuff then say -1 or what ever) wait() end