Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Leaderboard and leaderstats problem?

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?

3 answers

✓ Accepted answer

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

5 comments

0

lol it wouldnt work in ReplicatedStorage soooooo

0

why would you put it in replicated storage??

0

also making a folder is rather stupid and takes long, you can make one and clone it whenever they join

0

because putting it in replicatedstorage can allow me to use parent to quickly get the values

0

do you even know what your saying?? because you aren't making sense..

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)

4 comments

0

basically destroy the value and make a new one

0

terrible answer

0

how is this terrible? it fix the thing and it can be changed dynamically? whats the issue?

0

just sayin, but that approach isn't very friendly

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

5 comments

0

5/10

0

i try it

0

it wouldnt work lol

0

sorry but what i want its a script in the workspace (for complicated reason)

0

try again i edited it

This discussion is preserved as it was. New answers, comments, and votes are closed.