Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help with getting the player from the character?

I am trying to get the player and load it when a player touches it but I get this error: Workspace.Map.LoadChar.Script:5: attempt to index local 'plr' (a nil value)

script.Parent.Touched:connect(function(hit)
	local hum = hit.Parent:FindFirstChild('Humanoid')
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if hum then
		plr:LoadCharacter()
	end
end)

1 answer

Try checking for the player instead of the Humanoid

I'm not sure, but maybe an NPC touched the part or something.

script.Parent.Touched:connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        plr:LoadCharacter()
    end
end)

Try that :3

Good Luck!

This discussion is preserved as it was. New answers, comments, and votes are closed.