Okay, so let me explain what I wanted. And what the problem is, before I present the script. Okay so I made a gui with a text button. And it is supposed to take you from the lobby to the game, then after it does the text changes from "Game" to "Lobby", and when you click it again it is supposed to take you back to the lobby, then repeat this. The problem is that when you click it takes you to the game, then text changes to "Lobby" but when you click, it doesn't take you to the lobby part I am using the positions of the parts and idk if it is how I am doing it or not. And I am wondering how will I make it repeat? I've been working on it for a while, and I'd appreciate if anyone has a idea or clue how to fix this? Or make it better??
SCRIPT
local ingame = false wait(.5) game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton.Text = ("Game") script.Parent.MouseButton1Click:Connect(function() game.Players.LocalPlayer.character.Torso.CFrame = CFrame.new(workspace.gameT.position) if ingame == false then wait(.1) game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton.Text = ("Lobby") script.Parent.MouseButton1Click:Connect(function() game.Players.LocalPlayer.character.Torso.CFrame = CFrame.new(workspace.lobbyT.Position) wait(.1) end) end end)
here is a gif of what happens too btw: https://gyazo.com/11489be121de4cff760bfb71b6a9d695
Workspace --> gameT (part) --> lobbyT(part)
StarterGui --> ScreenGui -->TextButton --> LocalScript
The button's text has started with "Teleport to game"
Here is the script I made:
-- Variables local player = game:GetService("Players").LocalPlayer local button = script.Parent local switch = true gameLocation = game:GetService("Workspace").gameT.Position -- Make sure your location is set the game part you want to teleport to lobbyLocation = game:GetService("Workspace").lobbyT.Position -- or lobby part function clicked() -- Changes the text, moves the character to the position of the part, and changes the boolean to the opposite boolean depending if the boolean is true or false if (switch) then button.Text = "Teleport to lobby" player.Character.HumanoidRootPart.CFrame = CFrame.new(gameLocation) switch = false else button.Text = "Teleport to game" player.Character.HumanoidRootPart.CFrame = CFrame.new(lobbyLocation) switch = true end end -- When the button is clicked, run the function clicked() button.MouseButton1Click:Connect(clicked)