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

How to fix Humanoid is not a valid member of Accessory?

I am trying to make a teleport pad and keep getting this error. How can I fix?

local Pad2 = game.Workspace.TeleportPad2

script.Parent.Touched:Connect(function(touchPart)

if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and

touchPart.Parent.currentlyTeleporting.Value == false then

local Character = touchPart.Parent

local teleportLocation = CFrame.new(Pad2.CFrame.X, Pad2.CFrame.Y + 5, Pad2.CFrame.Z)

Character:SetPrimaryPartCFrame(teleportLocation)

	local teleportingValue = Character.currentlyTeleporting
	teleportingValue.Value = true
	wait(3)
	teleportingValue.Value = false
end

end)

1 answer

✓ Accepted answer

I think I might know what the problem is here. The script might be better to look more like this:

local Pad2 = game.Workspace.TeleportPad2

script.Parent.Touched:Connect(function(touchPart)
	local Humanoid = touchPart.Parent:FindFirstChild("Humanoid")
	if touchPart and touchPart.Parent and Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then

		local Character = touchPart.Parent

		local teleportLocation = CFrame.new(Pad2.CFrame.X, Pad2.CFrame.Y + 5, Pad2.CFrame.Z)

		Character:SetPrimaryPartCFrame(teleportLocation)

 		local teleportingValue = Character.currentlyTeleporting
		 teleportingValue.Value = true
 		wait(3)
		 teleportingValue.Value = false
	end
end)

What has been changed?

  • I have replaced and touchPart.Parent.Humanoid in line 5 with Humanoid. to check if the humanoid from the line I added at line 4 local Humanoid = touchPart.Parent:FindFirstChild("Humanoid") simply trying to get it, returning nil if nothing is there exists.

What is this doing?

  • This is checking to make sure that it can actually find a item called Humanoid. In your code its just telling it where the Humanoid is meant to be.

1 comment

0

Thanks it works man. You the goat

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