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

Touched is not a valid number of model?

So I am trying to create a teleporter but when I test it out it doesn't work. I looked in the output and it tells me "Touched is not a valid number of model"

My workspace:

-Lobby

Humanoid, Head, Part,

-Part

Mesh, Script

Script:

script.Parent.Parent.Touched:connect(function(hit)
	if hit.Parent.Parent:FindFirstChild('Humanoid') then
		hit.Parent.Parent.Torso.CFrame = CFrame.new(56, 5.1, -5116.002)
		
		
	end
end)

Please help me thank you.

2 answers

✓ Accepted answer

Your parents don't point to the part, they're pointing to the model. Take one Parent off.

local part = script.Parent -- It's good practice to index your items, it's easier to read and visualize.  
part.Touched:connect(function(hit) -- Parent removed
-- Removed a parent here as well
-- Standard practice to make sure what we hit isn't nil 
	if hit and hit.Parent then 
	-- grabs player from character (hit.Parent)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
		-- Make sure it's a player and their character is loaded.
		if player and player.Character then
			local hum = player.Character:findFirstChild("Humanoid") 
			-- Don't want to move if they just died on the teleporter
			if hum and hum.Health > 0 then
				player.Character:MoveTo(Vector3.new(56, 5.1, -5116.002))
			end
		end
	end
end)

I also made a teleporter, but I used another part for the player to teleport to.

local telestart = script.Parent
local teleend = game.Workspace.TeleEnd

function teleportPlayer(part)
	local torso = part.Parent:FindFirstChild("Torso")
		torso.CFrame = CFrame.new(teleend.Position) + Vector3.new(0,10,0)
		print(1)	--For testing
	end
	


telestart.Touched:connect(teleportPlayer)

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