Ad
Log in to vote
0

Coins script doesn't add coins to leaderstats?

Asked by 9 days ago

I'm making a Script that adds Coins to the player's leaderstats.

It's supposed to add Coins but it doesn't and doesn't work.

Script Analysis and Output didn't even say what was wrong

FE is disabled

game.Players.PlayerAdded:connect(function(player)
    if player:FindFirstChild("leaderstats") then
        local Coins = Instance.new["IntValue"]
        Coins.name = "Coins"
        Coins.Value = 0
        Coins.Parent = player.leaderstats
    end
end)

while wait(10) do 
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player:FindFirstChild("leaderstats") then
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
        end
    end
end
0
It is obvious you didn't check the out put... It would have said "name" a nil global or something like that and u should try WaitForChild instead of find first child greatneil80 221 — 9d

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

2 answers

Log in to vote
0
Answered by
Thetacah 284
9 days ago
Edited 9 days ago

heyyo,

First things first, you're using the FindFirstChild method on something you have not created yet! You need to create something in the player named "leaderstats" yourself. Usually of the type model or folder.

So, we can create leaderstats, and remove your if statement.

Secondly, when creating Instances, you cannot use square brackets. You are to use parentheses ().

Thirdly, "Name" had to be capitalized since lua is a case sensitive language.

game.Players.PlayerAdded:connect(function(player)

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats" 
    leaderstats.Parent = player
      local Coins = Instance.new("IntValue")
      Coins.Name = "Coins"
      Coins.Value = 0
      Coins.Parent = leaderstats

end)

while wait(10) do 
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player:FindFirstChild("leaderstats") then
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
        end
    end
end
0
Every scripting language is case sensitive. hiimgoodpack 660 — 9d
0
There's already a leaderstats intvalue, It's created by a premade linkedleaderboard script that served a purpose for KO's robertwoodsy5115 12 — 9d
Ad
Log in to vote
0
Answered by 9 days ago

Fixed

game.Players.PlayerAdded:connect(function(player)
    local stats = Instance.new('Folder', player)
    stats.Name = 'leaderstats'
    local coins = Instance.new('IntValue', stats)
    coins.Name = 'Coins'
    coins.Value = 0
    while wait(10) do
        player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
    end
end)

Answer this question



Ad