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

Teleport player when they press a gui button?

This isnt working for some reason. Its in a local script inside the button

script.Parent.MouseButton1Down:connect(function()
    local localplayer = game.Players.LocalPlayer.Name
	print(localplayer)	
	wait(1)
	localplayer.Torso.CFrame = CFrame.new(Vector3.new(1479.5, 10.7, -398))
end)

1 comment

2

You are accessing the Name which is a string not the character use LocalPlayer.Character

1 answer

✓ Accepted answer

As kingdom5 said in his comment, you need to use the player's Character rather than their Name.

script.Parent.MouseButton1Down:Connect(function() --use uppercase C Connect
    local char = game.Players.LocalPlayer.Character
    if not char then
        return --abort if they don't have a character
    end
    wait(1)
    chaar.HumanoidRootPart.CFrame = CFrame.new(1479.5, 10.7, -398)
    --^ use HumanoidRootPart instead of Torso               ^ you don't have to use Vector3.new()
end)

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