-
I’m making a simple script for when a player walks through a door (collides with a part) It loads a BlackLoadingScreen GUI and teleports the player to the end location, then loads the FactoryGUI
-
Issue is that whenever the player goes through the door, it repeatedly clones the GUI a bunch of times.
-
I only want it to clone once, I’ve tried fixing it but It’s just not seeming to work.
SCRIPT LOCATED IN StarterGui.BlackFadingScreen.Frame
-- Script for teleporting a player to another part's position upon collision
local teleportPart = game.Workspace.touchedPart
local defaultFactory = game:GetService("Workspace").DefaultFactory -- Assuming this script is a child of the teleporting part
local destinationPart = defaultFactory.Utils.endPart
local Players = game:GetService("Players") -- Replace with the name of the destination part
local RepStorage = game:GetService("ReplicatedStorage")
local function onTouched(other)
local character = other.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local player = Players:GetPlayerFromCharacter(character)
local facGUIloaded = false
-- If touched by a player's humanoid, teleport the player to the destination part
if humanoid then
local facGUI = RepStorage.FactoryGUI:Clone()
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
facGUI.Parent = player.PlayerGui
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)