so i'm making an obby game. when a player touches the end they get 10 coins. or that's what supposed to happen. when the player touches the end sometimes they get 10 coins and other times nothing happenes, and an error appears in the output. the error is something like "attempt to index nil with leaderstats" here's the script.
script.Parent.Touched:Connect(function(plr) game.Players:GetPlayerFromCharacter(plr.Parent).leaderstats.Coins.Value = game.Players:GetPlayerFromCharacter(plr.Parent).leaderstats.Coins.Value + 10 end)
thanks!
It's better to do this:
script.Parent.Touched:Connect(function(plr) local leaderstats = game.Players:GetPlayerFromCharacter(plr.Parent):WaitForChild("leaderstats") leaderstats.Coins.Value = leaderstats.Coins.Value + 10 end)