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

attempt to index nil with character?

attempt to index nil with character, the script should work this way, u touch it and it anchores your head, it isnt really what i need to do completely

local part = workspace.ts4

part.Touched:wait()

player.Character.Head.Anchored = true

function onPartTouched()
	player.Character.Head.Anchored = true
end

part.Touched:connect(onPartTouched)

the ''player'' is blue below that i think its nil btw dont take down, i tried

1 answer

✓ Accepted answer

player is a variable you have to set. You can get it by using game.Players:GetPlayerFromCharacter(model), which returns nil if the model isn't from a player character. It can be set in localscripts with local player = game.Players.LocalPlayer. BUT you are using a part.Touched event, so you don't need a player unless you want to mess with it too or to rule out npcs. Set a variable for the touched part:

player.Character.Head.Anchored = true

function onPartTouched(touch)
	if touch.Parent:findFirstChild("Humanoid") then --makes sure part is from a humanoid
		touch.Parent.Head.Anchored = true
	end
end

part.Touched:connect(onPartTouched)

1 comment

0

thansk

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