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

GUI Player Teleporter? Help!

Asked by 7 years ago

So I'm trying to make a GUI where you type in the players name you would like to teleport but so far nothing happens when I do so. The script is located in a button. I am sure I have got my player directly targeted.

playerselect = script.Parent.Parent.PlayerSelect.Text

script.Parent.MouseButton1Down:connect(function()
    local choose = script.Parent.Parent:FindFirstChild(playerselect.Text)
    for i,v in pairs(game.Players:GetChildren()) do
        if v.Name == choose then
            local target = v.Character.Torso.Position
            script.Parent.Parent.Parent.Parent.Parent.Parent.Character.Torso.Position = CFrame.new(target)

        end
    end
end)

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I notice a few errors with this.
The first might not be an issue, but it looks suspicious: is the TextBox PlayerSelect or Text? If it's PlayerSelect, then the line should be this:

playerselect = script.Parent.Parent.PlayerSelect

Next, the for loop is probably not necessary, since there will only be up to one player with the name specified. You can achieve the same effect with this:

local player = game.Players:FindFirstChild(playerselect.Text)
if player then
    -- Rest of code here.
end

Finally, you're trying to set the Position of the character (a Vector3 value) to a CFrame. Since this won't work, you should do this instead:

local target = player.Character.Torso.CFrame
-- The long .Parent chain is not necessary; note that this requires a local script to work.
game.Players.LocalPlayer.Character.Torso.CFrame = target

The complete code should look like this:

playerselect = script.Parent.Parent.PlayerSelect

script.Parent.MouseButton1Down:connect(function()
    local player = game.Players:FindFirstChild(playerselect.Text)
    if player then
        local target = player.Character.Torso.CFrame
        game.Players.LocalPlayer.Character.Torso.CFrame = target
    end
end)
0
The one problem is would that work as a local script because Im making a game with FE AuthenticOakChair 68 — 7y
0
When your script needs to change something like a part's CFrame, a server script would be best. FilteringEnabled would mess up everything then. EzraNehemiah_TF2 3552 — 7y
0
There is surely a way to work around that. AuthenticOakChair 68 — 7y
0
Oh and btw i tried your code without FE in a local script and I got "Argument 1 missing or nil" AuthenticOakChair 68 — 7y
Ad

Answer this question