Part of Script only Running Once

  1. My script is when I walk through a door it loads a LoadingScreen GUI and teleports me into a Job.

  2. The Issue is that I go through the door to my Job then I teleport back to spawn but when I go back through the door it is not reloading my GUI.

(Script TP’s Player to Job) Located in StarterGui.LoadingScreen.Frame V

-- Script for teleporting a player to another part's position upon collision
local teleportPart = game.Workspace.touchedPart -- Assuming this script is a child of the teleporting part
local destinationPart = game.Workspace:WaitForChild("endPart")  -- Replace with the name of the destination part

local function onTouched(other)
	local character = other.Parent
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")

	-- If touched by a player's humanoid, teleport the player to the destination part
	if humanoid then
		local gui = script.Parent
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
		local tween = game:GetService("TweenService"):Create(gui, tweenInfo, {BackgroundTransparency = 0})
		gui.Visible = true
		tween:Play()
		wait(2)
		character.HumanoidRootPart.CFrame = destinationPart.CFrame
		gui.Parent.Parent.FactoryGUI.Enabled = true
		gui.Parent.Parent.FactoryGUI.ParentFrame.Visible = true
		gui.Parent.Parent.VHs.Enabled= true
		wait(0.25)
		local tweenInfo2 = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
		local tween2 = game:GetService("TweenService"):Create(gui, tweenInfo2, {BackgroundTransparency = 1})
		tween2:Play()
		wait(1.5)
		gui.Visible = false	
	end
end
-- Connect the 'Touched' event of the teleport part to the 'onTouched' function
teleportPart.Touched:Connect(onTouched)

(Script TP’s Player Back) Located in StarterGui.FactoryGUI.ParentFrame.MainFrame.StartShift.startButton

local button = script.Parent

button.MouseButton1Click:Connect(function()
    local parentFrame = button:FindFirstAncestorWhichIsA("ScreenGui").ParentFrame
    local viewedStats = button:FindFirstAncestorWhichIsA("ScreenGui").ViewShift.viewedstats
    parentFrame.Visible = false
    viewedStats.Visible = true
end)

Why don’t you just store the gui somewhere else and when the player enters you clone the gui and when they leave you destroy the gui. Another wey you could do this is by having a function that resets all the gui values to their original values

That is a viable option but it is puzzling on why it only runs once and never again. I check my players local startergui and double checked my code was referencing the right child & property.