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

why this teleport by clicking a text button script doesn't work?

title explains

script.Parent.MouseButton1Click:Connect(function()
	local plr = game.Players:WaitForChild(game.Workspace.PlayerName.Value)
	local char = plr.Character
	local torso = char:WaitForChild("Torso")
	torso.Position = script.Parent.Parent.Parent.Parent.Receiver.Position
end)

the game is r6 only so it should find torso no errors

3 answers

✓ Accepted answer

ok i just did char:MoveTo(script.Parent.Parent.Parent.Parent.Receiver.Position) and it works

I recommend you use CFrames, they are much more efficient. When we are changing a Player's Position via a script, it is much better to use HumanoidRootPart rather than the Player's Torso. R15 and R6, both contain a HumanoidRootPart within them. In this case, we want to change the HumanoidRootPart's CFrame to the Receiver's CFrame.

script.Parent.MouseButton1Click:Connect(function()
    local plr = game.Players:WaitForChild(game.Workspace.PlayerName.Value)
    local char = plr.Character or Player:WaitForChild("Character")
    local HRP = char:WaitForChild("HumanoidRootPart")
    HRP.CFrame = script.Parent.Parent.Parent.Parent.Receiver.CFrame
end)

Alright, I might have a solution.

When I looked at the output, it said "PlayerName is not a valid member of Workspace"

I do have a script that might work.

Place it as a local script in the Text Button, then add a part, then name it exactly "TP" without the quotes.

script.Parent.MouseButton1Click:Connect(function()
	game.Players.LocalPlayer.character.LowerTorso.CFrame = CFrame.new(workspace.TP.Position) 
	wait(0.1)
end)

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