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

Coins script doesn't add coins to leaderstats?

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

1 comment

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

2 answers

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)

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

2 comments

0

Every scripting language is case sensitive.

0

There's already a leaderstats intvalue, It's created by a premade linkedleaderboard script that served a purpose for KO's

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