Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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

Ad
Log in to vote
0
Answered by 4 years ago

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)
Log in to vote
0
Answered by 4 years ago

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)

Answer this question