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

Why does the value "player" keep returning as nil?

Asked by 6 years ago

The value "player" is supposed to return as the username of the player who hit the part, but it just keeps returning as nil and I don't know why. Any ideas?

local finditems = script.Parent:GetChildren()
for i=1,#finditems do
if finditems[i].Name == "block" then
finditems[i].HumanoidRootPart.Touched:connect(function(hit)
print(finditems[i].coins.Value)
if finditems[i].debounce.Value == false then
finditems[i].debounce.Value = true

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.Status.Credits.Value = player.Status.Credits.Value + finditems[i].coins.Value

local blockanim = finditems[i].Humanoid:LoadAnimation(finditems[i].BlockAnim)
blockanim:Play()
wait(finditems[i].debouncetime.Value)
finditems[i].debounce.Value = false
end
end)
end
end

Answer this question