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!
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
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