You may have seen a previous question I've asked about this issue, but this time I believe I am closer to finding the solution. However, this time, I have a problem that may be simple to solve, but I just can't see the solution.
I'm trying to make a GUI that can be pressed to bring a player to a sort of hub, and then pressed again to be returned to their previous location prior to the first press. The hub location is fixed at a part's CFrame, while the previous position is recorded before the function decides if the player is going to the hub or their previous location.
My problem is that the function goes through both conditions of the script, instead of only going through the true or false condition. I've tried using "else" instead of "if", moving the locations of "end", and moving the locations of one condition enabling another for the next use of the function, yet nothing has worked.
Here's a look at the script:
local Event = game.ReplicatedStorage.TeleEvent
local inHub = false
local HubWarp = workspace.HubWarp
Event.OnServerEvent:Connect(function(player)
local oldpos = player.Character.HumanoidRootPart.CFrame
local char = player.Character
if inHub == false then
inHub = true
char.HumanoidRootPart.CFrame = HubWarp.CFrame
print("Going to hub...")
end
if inHub == true then
inHub = false
char.HumanoidRootPart.CFrame = oldpos
print("Going to previous location...")
end
end)
And the local script, if necessary:
Event = game.ReplicatedStorage.TeleEvent
player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
Event:FireServer(player)
print("Fired")
end)
Additional information: The script is in ServerScriptService. The Local Script is in a ScreenGui. In output, all printable phrases are printed in one mouse click. It goes in the order of "Fired", "Going to hub...", "Going to previous location...". In-game, the player does not appear to move.
