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

Teleport GUI malfunction?

Asked by
JJ_B 250 Moderation Voter
9 years ago

I made a GUI where when a TextButton is pressed, the name inputted in an above TextBox teleports the corresponding character to a part's CFrame. Here's the script:

b = script.Parent.Parent.name.Text

function transport()
    if b == game.Workspace:FindFirstChild(b) then
        game.Workspace.b.Torso.CFrame = game.Workspace.planetbeam.CFrame + CFrame.new(0,5,0)
        script.Parent.Parent.Parent.Parent:Destroy()
    else return end
end

script.Parent.MouseButton1Click:connect(transport)

It just doesn't do anything and the output says nothing. Help!

0
Are you trying to teleport other players or to teleport a certain player to a part VariadicFunction 335 — 9y
0
Like do you want a button saying "Player 2" and it teleports player2 to that part OR do you want it to say "Platform 3" and it teleports you there.. VariadicFunction 335 — 9y
0
What happens is someone types in a name in the TextBox and presses the button, and it's meant to teleport the player that has been typed in JJ_B 250 — 9y
0
Alright VariadicFunction 335 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

A problem with your code was that you compared a string to an object found (or not found) in game.Workspace so I just made it so that if the object exists then proceed. Also you can't use properties as variables unless you want the current value rather than the value as it changes.

From there you should get the players character, rather than setting the torso CFrame. I'm not quite sure why you want to do script.Parent.Parent.Parent:Destroy() but I'm assuming you want to keep that. This should only teleport if the player's character is present and the humanoid exists and is alive. If you encounter any glitches comment on here so I can figure them out.

b = script.Parent.Parent.name

function transport()
    local player = game.Players:FindFirstChild(b.Text)
    if player and player.Character then 
        local character = player.Character
        if character:FindFirstChild("Humanoid") and character.Humanoid.Health > 0 then
            character:MoveTo(game.Workspace.planetbeam.Position + Vector3.new(0,5,0))
            script.Parent.Parent.Parent.Parent:Destroy()
        end
    end
end

script.Parent.MouseButton1Click:connect(transport)

NOTE: You shouldn't really use "name" as the name of the text box because that could cause problems. It might not but either way it's bad practice because it could read it as the Name property of script.Parent.Parent, rather than the text box

0
Thanks a lot for your help! The "script.Parent.Parent.Parent.Parent:Destroy()" was to destroy the GUI after the button was pressed. JJ_B 250 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

The script below will teleport the player:-

function transport()
    local txt = script.Parent.Parent.TextBox.Text --gets the gui text
    local wPlr = game.Workspace:FindFirstChild(txt) --gets the player

    if wPlr ~= nil  then --Check is the playe exists
        local planetBeam = game.Workspace.planetbeam.CFrame  -- get the position 
        wPlr.Torso.CFrame = CFrame.new(planetBeam.X,  planetBeam.Y+5, planetBeam.Z) --moves player to the position
        script.Parent.Parent.Parent.Parent:Destroy()
    else return end
end

script.Parent.MouseButton1Click:connect(transport)

This line you are comparing the name to the object of the player not the text of the player so it will not run.

 if b == game.Workspace:FindFirstChild(b) then

Hope this helps

Answer this question