Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Da_ve5 0
5 years ago
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

Log in to vote
0
Answered by 5 years ago

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)
0
thanks Da_ve5 0 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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)
0
it doesn't have to be a model, it can be anything with the name "leaderstats" theking48989987 2147 — 5y

Answer this question