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
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