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

Teleport GUI malfunction?

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!

4 comments

0

Are you trying to teleport other players or to teleport a certain player to a part

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

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

0

Alright

2 answers

✓ Accepted answer

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

1 comment

0

Thanks a lot for your help! The "script.Parent.Parent.Parent.Parent:Destroy()" was to destroy the GUI after the button was pressed.

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

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