local db = true local playerstats = game.Players:FindFirstChild("leaderstats") script.Parent.ClickDetector.MouseClick:connect(function(onClicked) if db == true then db = false script.Parent.Transparency = 1 playerstats.Robux.Value = playerstats.Robux.Value + 10 script.Parent.Sound:Play() script.Parent.ParticleEmitter.Enabled = false wait(10) db = true script.Parent.Transparency = 0 script.Parent.ParticleEmitter.Enabled = true end end)
I tested this script and it said this in the output:
"16:41:40.424 - Workspace.Soda Can.CollectScript:10: attempt to index a nil value"
I've tried multiple things to fix such as changing up the variable, and nothing seems to work. Any help would be greatly appreciated.
Why are you trying to find "leaderstats" in Players? It obviously errors because "leaderstats" does not exist under Players. (assuming that leaderstats is an IntValue)
Here is the correct way of your code:
local db = true script.Parent.ClickDetector.MouseClick:Connect(function(Player) local playerstats = Player:FindFirstChild("leaderstats") if db == true then db = false script.Parent.Transparency = 1 playerstats.Robux.Value = playerstats.Robux.Value + 10 script.Parent.Sound:Play() script.Parent.ParticleEmitter.Enabled = false wait(10) db = true script.Parent.Transparency = 0 script.Parent.ParticleEmitter.Enabled = true end end)