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

anybody fix?(Workspace.heart.collect:4: attempt to index local 'player' (a nil value))

Asked by
qVoided 221 Moderation Voter
4 years ago
Edited 4 years ago
script.Parent.Touched:Connect(function(hit)

    if hit.Parent:FindFirstChild("Humanoid") then

        local player = game.Players:GetPlayerFromCharacter(hit.Parent)

        local leaderstats = player:WaitForChild("leaderstats")
        local hearts = leaderstats.Hearts

        hearts.Value = hearts.Value + 1

        script.Parent:Destroy()

    end
end)

it works but it keeps giving me an error:

Workspace.heart.collect:4: attempt to index local 'player' (a nil value)

can anybody fix my script please?

i appreciate it.

0
Could you please change the code to a more readable code block? Is this your entire code? And is it exactly like this you have it in the script? Hard to help with an error if you change anything Spjureeedd 385 — 4y
0
ok, i didn't notice that, thanks qVoided 221 — 4y
0
remove the GetPlayerFromCharacter and the () parker02311 27 — 4y

Answer this question