Ad
Log in to vote
0

Coins script doesn't add coins to leaderstats?

Asked by 5 months 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 276 — 5mo

2 answers

Log in to vote
0
Answered by
Thetacah 335
5 months ago
Edited 5 months 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 1535 — 5mo
0
There's already a leaderstats intvalue, It's created by a premade linkedleaderboard script that served a purpose for KO's robertwoodsy5115 12 — 5mo
Ad
Log in to vote
0
Answered by 5 months 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