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

Please help my script keeps breaking and not working? (Read desc)

print("Cash Leaderboard Loaded")


function onPlayerEntered(newPlayer)

	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local cash = Instance.new("IntValue")
	cash.Name = "Money"       --name of currency (e.g. cash, money, resources, bucks, etc.)
	cash.Value = 1000      --starting money.

	cash.Parent = stats
	stats.Parent = newPlayer
end



game.Players.ChildAdded:connect(onPlayerEntered)
end
  end

game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new("IntValue", p)
stats.Name = "leaderstats"
local money = Instance.new("IntValue", stats)
money.Name = "Cash"
money.Value = 100
while true do
wait(5)
money.Value = money.Value + 10
end
end)

It won't give me money nor I can't see it on the leaderboard. Please help.

2 answers

Hey,

You've got two unnecessary "end"s on line 20 and 21.

You usually have an end after an if, an function and so on.

I also changed ChildAdded to PlayerAdded, that is better and then it wont break if something else is inserted into Players.

Here is the code with the problem solved:

print("Cash Leaderboard Loaded")


function onPlayerEntered(newPlayer)

    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local cash = Instance.new("IntValue")
    cash.Name = "Money"       --name of currency (e.g. cash, money, resources, bucks, etc.)
    cash.Value = 1000      --starting money.

    cash.Parent = stats
    stats.Parent = newPlayer
end



game.Players.PlayerAdded:connect(onPlayerEntered)

game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new("IntValue", p)
stats.Name = "leaderstats"
local money = Instance.new("IntValue", stats)
money.Name = "Cash"
money.Value = 100
while true do
wait(5)
money.Value = money.Value + 10
end
end)

1 comment

0

thanks

The first problem is that when you are making a leaderboard you first have to make a model and name it 'leaderstats'.

This will work, I removed the first function because I didn't see the purpose of it

print("Cash Leaderboard Loaded")

game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new("Model")
stats.Parent = p
stats.Name = "leaderstats"
local money = Instance.new("IntValue")
money.Parent = stats
money.Name = "Cash"
money.Value = 100
while true do
wait(5)
money.Value = money.Value + 10
end
end)

1 comment

0

it doesn't have to be a model, it can be anything with the name "leaderstats"

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