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.

3 comments
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
ok, i didn't notice that, thanks
remove the GetPlayerFromCharacter and the ()