Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone tell me what is wrong with my script? (More details in desc.)

Asked by
Nump4d 5
4 years ago
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.

0
You Are Looking In Players For 'playerstats' which is not Players UnforgivenJr3087 26 — 4y
0
i just named the variable that, does it really matter? Nump4d 5 — 4y

1 answer

Log in to vote
1
Answered by
p0vd 207 Moderation Voter
4 years ago
Edited 4 years ago

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)

0
Please upvote this if this helped. p0vd 207 — 4y
0
thanks this fixed it :) Nump4d 5 — 4y
Ad

Answer this question