Teleport with module script

I just write script that teleport player to “a” object in workspace but my code not working

	{
		KeyCode = Enum.KeyCode.E;
		Description = 'Teleport';
		Function = function()
			local Teleport = "a" 
	if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true --Checks Debounce.
	local Pos = script.Parent.Parent:findFirstChild(Teleport) --Gets the Part to teleport to.
		moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end 
		 
	};
	{
1 Like

Changed code this should be better

        place = CFrame.new(0,0,0) -- Where you want the player to go on touched
script.Parent.Touched:connect(function(p)--Creating the function
local humanoid = p.Parent:findFirstChild("Humanoid")--Trying to find the humanoid
if (humanoid ~= nil) then -- Checking if what touched it IS a player.
humanoid.HumanoidRootPart.CFrame = place -- Moves the torso to what is specified in the place variable
end
end

But now getting this error on console

HumanoidRootPart is not a valid member of Humanoid "Workspace.Sarptra.Humanoid"  -  Client - Interaction:10
  17:28:13.424  Stack Begin  -  Studio
  17:28:13.425  Script 'Workspace.AllInteractions.TestInteraction.Interaction', Line 10  -  Studio - Interaction:10

Try changing the 5th line to p.Parent.HumanoidRootPart

1 Like
 HumanoidRootPart is not a valid member of Model "Workspace.Sarptra"  -  Client - Interaction:10
  17:32:15.107  Stack Begin  -  Studio
  17:32:15.108  Script 'Workspace.AllInteractions.TestInteraction.Interaction', Line 10  -  Studio - Interaction:10
  17:32:15.109  Stack End  

Same error

Changed to p.Parent.HumanoidRootPart = place

Try adding a wait for child, like this:

local character = player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

-- WaitForChild() waits for something to load.

This might fix it, it seems like it has not loaded yet into the player’s character judging by the error…

Ok I solved thanks a lot ! + removed something from code