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

How do I get the character from humanoid ?

Hello ! I was wondering how, in my script, I can get the value contained in the character, having the humanoid object.

function changeDefault(part)
	if part.Parent:FindFirstChild("Humanoid").Parent.IsHuman then
		local character = part.Parent:FindFirstChild("Humanoid")
		changeSky:FireClient(game.Players:GetPlayerFromCharacter(character.Parent), "Default")
	end
end

The error message is :

ServerScriptService.Regions:30: attempt to index nil with 'Parent'

1 answer

✓ Accepted answer

So basically you can just check for the humanoid because the parent will always be a player as long as you have not added another humanoid yourself.

function changeDefault(part)
	local character = part.Parent:FindFirstChild("Humanoid")
	if character then
	        changeSky:FireClient(game.Players:GetPlayerFromCharacter(character.Parent), "Default")
	end
end

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