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

Teleport player when they press a gui button?

Asked by 5 years ago

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)

2
You are accessing the Name which is a string not the character use LocalPlayer.Character User#5423 17 — 5y

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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)

Ad

Answer this question