Event fires once, function fires twice

Hmm… it seems like multiple copies of the script are running, especially with the changes you made to it. Could you try running this code and see what the output is? If only one script is running, the randomly generated number will be the same, but if multiple are running, it will be different.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LoadedIn = ReplicatedStorage:WaitForChild("Events"):WaitForChild("LoadedIn")
local CloseEvent = ReplicatedStorage.Events:WaitForChild("CloseTitle")
local SetFake = ReplicatedStorage.Events:WaitForChild("SetFake")

local Players = game.Players
local Player = Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Title = PlayerGui:WaitForChild("CharCustom")

local Frame = Title:WaitForChild("Frame")
local UIGradient = Frame:WaitForChild("UIGradient")
local AniModule = require(UIGradient:WaitForChild("Animator"))
local FadeIn = AniModule.FadeIn
local FadeOut = AniModule.FadeOut

local In = false

local CharEdit = ReplicatedStorage.Events:WaitForChild("CharEdit")
local ClientMaps = ReplicatedStorage:WaitForChild("ClientMaps")
local Room = ClientMaps:WaitForChild("CustomEditor")

local Workspace = game.Workspace
local part = Workspace.SpawnLocation
local fakeChar
local randomNumberTest = math.random()

CharEdit.Event:Connect(function(tthing)
	if fakeChar ~= true then
		print("AAAAA", randomNumberTest)
		print(tthing)
		Room.Parent = game.Workspace
		Title.Enabled = true
		FadeIn:Play()
		In = true
		Room.Parent = game.Workspace
		Player.Character.Archivable = true
		fakeChar = Player.Character:Clone()
		fakeChar.HumanoidRootPart.Position = Vector3.new(-587.5, 62.656, -84)
		fakeChar.HumanoidRootPart.Orientation = Vector3.new(0, -90, -0)
		fakeChar.Parent = game.Workspace
		fakeChar.Name = "FakeChar"
		Player.Character.Archivable = false
		SetFake:Fire(fakeChar)
		fakeChar = true
	end
end)

LoadedIn.Event:Connect(function()
	FadeOut:Play()
	task.wait(1.5)
	Title.Enabled = false
	Room.Parent = game.ReplicatedStorage.ClientMaps
	fakeChar = false
end)
1 Like

You’re right. Weird thing is, I changed the RunContext scripts to normal localscripts…
image
image

I fixed it. I had to wrap the entire script into an if statement, to make sure it wouldn’t do anything in StarterGui.

if script.Parent.Parent ~= game:GetService("StarterGui") then
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local LoadedIn = ReplicatedStorage:WaitForChild("Events"):WaitForChild("LoadedIn")
	local CloseEvent = ReplicatedStorage.Events:WaitForChild("CloseTitle")
	local SetFake = ReplicatedStorage.Events:WaitForChild("SetFake")

	local Players = game.Players
	local Player = Players.LocalPlayer
	local PlayerGui = Player.PlayerGui
	local Title = PlayerGui:WaitForChild("CharCustom")

	local Frame = Title:WaitForChild("Frame")
	local UIGradient = Frame:WaitForChild("UIGradient")
	local AniModule = require(UIGradient:WaitForChild("Animator"))
	local FadeIn = AniModule.FadeIn
	local FadeOut = AniModule.FadeOut

	local In = false

	local CharEdit = ReplicatedStorage.Events:WaitForChild("CharEdit")
	local ClientMaps = ReplicatedStorage:WaitForChild("ClientMaps")
	local Room = ClientMaps:WaitForChild("CustomEditor")

	local Workspace = game.Workspace
	local part = Workspace.SpawnLocation
	local fakeChar
	local randomNumberTest = math.random()

	CharEdit.Event:Connect(function(tthing)
		if fakeChar ~= true then
			print("AAAAA", randomNumberTest)
			print(tthing)
			Room.Parent = game.Workspace
			Title.Enabled = true
			FadeIn:Play()
			In = true
			Room.Parent = game.Workspace
			Player.Character.Archivable = true
			fakeChar = Player.Character:Clone()
			fakeChar.HumanoidRootPart.Position = Vector3.new(-587.5, 62.656, -84)
			fakeChar.HumanoidRootPart.Orientation = Vector3.new(0, -90, -0)
			fakeChar.Parent = game.Workspace
			fakeChar.Name = "FakeChar"
			Player.Character.Archivable = false
			SetFake:Fire(fakeChar)
			fakeChar = true
		end
	end)

	LoadedIn.Event:Connect(function()
		FadeOut:Play()
		task.wait(1.5)
		Title.Enabled = false
		Room.Parent = game.ReplicatedStorage.ClientMaps
		fakeChar = false
	end)
end
2 Likes