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

Player Teleportation Script Isn't Working. Why is this happening?

I have made a Player Teleportation Script, yet my script hasn't worked. I have gotten an error called Player is not a valid member of Part. Where did I go wrong?

local tela = script.Parent.TP1
local telb = script.Parent.TP2

function onTouch(part)
	local Player = part.Player:findFirstChild("Humanoid")
	if Player then
		Player.Parent.Torso.CFrame.new(telb.Position+Vector3.new(0,3,0))
	end
end

tela.Touched:Connect(onTouch)

1 answer

✓ Accepted answer

###This is because you were attempting to look for an object called Humanoid inside of an object called Player that doesn't exist, inside the part. You may want to index the Parent property instead, as this will be the player's character.

local tela = script.Parent.TP1
local telb = script.Parent.TP2

local function onTouch(part)
    local Player = part.Parent:FindFirstChild("Humanoid") 
    if Player then
        Player.Parent:SetPrimaryPartCFrame(CFrame.new(telb.Position+Vector3.new(0,3,0))
    end
end

tela.Touched:Connect(onTouch)

###On a side note, findFirstChild is deprecated, use FindFirstChild instead.

#####Hope this helped, ####- incapaz

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