I’m trying to make it so that when a player clicks on a button, it copies their player into my character customizer. Issue is, while the button fires once, the function goes off twice. I have checked, and there are no duplicate scripts.
Here’s the output:
The script that handles said button:
local Teams = script.Parent
local Human = Teams.Human
local Vamp = Teams.Vamp
local Wolf = Teams.Wolf
local Custom = Teams.Customizer
local Cams = game.Workspace.Cameras
local Cam = game.Workspace.Camera
local TeamSetter = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("SetTeam")
local CloseEvent = game.ReplicatedStorage.Events:WaitForChild("CloseTitle")
local Loaded = game.ReplicatedStorage.Events:WaitForChild("LoadedIn")
local CharEdit = game.ReplicatedStorage.Events:WaitForChild("CharEdit")
local cas = game:GetService("ContextActionService")
local plr = game:GetService("Players").LocalPlayer
local playerGui = plr:WaitForChild("PlayerGui")
local char = plr.Character
local Title = playerGui:WaitForChild("Title")
local DB = false
local blur = require(game.Lighting.Blur.Animator)
local tran = require(game.Lighting.Transition.Animator)
local function transition()
blur.Transition:Play()
tran.Transition:Play()
end
plr.CharacterAdded:Connect(function()
DB = false
char = plr.Character
TeamSetter:FireServer("Spirits")
cas:BindActionAtPriority("DisableControls",function()
return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.High.Value, unpack(Enum.PlayerActions:GetEnumItems()))
print("freeze")
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.Human.CFrame
Title.Enabled = true
end)
Human.MouseEnter:Connect(function()
if DB == false then
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.Human.CFrame
transition()
end
end)
Human.Activated:Connect(function()
if DB == false then
DB = true
TeamSetter:FireServer("Humans", Cams.Human)
Cam.CameraType = Enum.CameraType.Custom
Cam.CameraSubject = char.Humanoid
CloseEvent:Fire()
cas:UnbindAction("DisableControls")
end
end)
Vamp.MouseEnter:Connect(function()
if DB == false then
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.Vampire.CFrame
transition()
end
end)
Vamp.Activated:Connect(function()
if DB == false then
DB = true
TeamSetter:FireServer("Vampires", Cams.Vampire)
Cam.CameraType = Enum.CameraType.Custom
Cam.CameraSubject = char.Humanoid
CloseEvent:Fire()
cas:UnbindAction("DisableControls")
end
end)
Wolf.MouseEnter:Connect(function()
if DB == false then
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.Werewolf.CFrame
transition()
end
end)
Wolf.Activated:Connect(function()
if DB == false then
DB = true
TeamSetter:FireServer("Werewolves", Cams.Werewolf)
Cam.CameraType = Enum.CameraType.Custom
Cam.CameraSubject = char.Humanoid
CloseEvent:Fire()
cas:UnbindAction("DisableControls")
end
end)
Custom.Activated:Connect(function()
if DB == false then
print(DB)
DB = true
CharEdit:Fire()
print("fired")
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.CharEdit.CFrame
end
end)
Loaded.Event:Connect(function()
DB = false
end)
The script with the function that clones the character.
local LoadedIn = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("LoadedIn")
local CloseEvent = game.ReplicatedStorage.Events:WaitForChild("CloseTitle")
local Title = game.Players.LocalPlayer.PlayerGui:WaitForChild("CharCustom")
local AniModule = require(Title:WaitForChild("Frame"):WaitForChild("UIGradient"):WaitForChild("Animator"))
local FadeIn = AniModule.FadeIn
local FadeOut = AniModule.FadeOut
local In = false
local CharEdit = game.ReplicatedStorage.Events:WaitForChild("CharEdit")
local Room = game.ReplicatedStorage:WaitForChild("ClientMaps"):WaitForChild("CustomEditor")
local Player = game.Players.LocalPlayer
local part = game.Workspace.SpawnLocation
local fakeChar
local SetFake = game.ReplicatedStorage.Events:WaitForChild("SetFake")
CharEdit.Event:Connect(function()
print("AAAAA")
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)
end)
LoadedIn.Event:Connect(function()
FadeOut:Play()
task.wait(1.5)
Title.Enabled = false
Room.Parent = game.ReplicatedStorage.ClientMaps
end)
(Yes, Ik this is very spaghetti code-y, I’ll work on that once I get it to even function.)
Try deleting the event and see where it errors (first fire), then try deleting the event immediately after you fire it in your code to see if it errors then (second fire?). I really can’t tell what’s going on here because from what’s posted it should be working. It has to be 2 fires though somehow.
I also usually get this issue on my scripts and the way that i fixed it by adding a boolean to check if the remoteEvent fired, it’s something similar like
Custom.Activated:Connect(function()
local fired = false
if DB == false then
print(DB)
DB = true
if fired == false then
CharEdit:Fire()
fired = true
end
print("fired")
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.CharEdit.CFrame
end
end)
Which could probably fix the issue that you’re having
Those are all scripts that use it. None are duplicates
All use the function, but do different things, I just checked.
I also did the check before the event fires.
print("ey homeboy")
local fired = false
if DB == false then
print(DB)
DB = true
if fired == false then
CharEdit:Fire()
fired = true
end
print("fired")
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.CharEdit.CFrame
end
end)
local Teams = script.Parent
local Human = Teams.Human
local Vamp = Teams.Vamp
local Wolf = Teams.Wolf
local Custom = Teams.Customizer
local Cams = game.Workspace.Cameras
local Cam = game.Workspace.Camera
local TeamSetter = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("SetTeam")
local CloseEvent = game.ReplicatedStorage.Events:WaitForChild("CloseTitle")
local Loaded = game.ReplicatedStorage.Events:WaitForChild("LoadedIn")
local CharEdit = game.ReplicatedStorage.Events:WaitForChild("CharEdit")
local cas = game:GetService("ContextActionService")
local plr = game:GetService("Players").LocalPlayer
local playerGui = plr:WaitForChild("PlayerGui")
local char = plr.Character
local Title = playerGui:WaitForChild("Title")
local DB = false
local blur = require(game.Lighting.Blur.Animator)
local tran = require(game.Lighting.Transition.Animator)
local function transition()
blur.Transition:Play()
tran.Transition:Play()
end
plr.CharacterAdded:Connect(function()
print("DB exists")
DB = false
char = plr.Character
TeamSetter:FireServer("Spirits")
cas:BindActionAtPriority("DisableControls",function()
return Enum.ContextActionResult.Sink
end, false, Enum.ContextActionPriority.High.Value, unpack(Enum.PlayerActions:GetEnumItems()))
print("freeze")
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.Human.CFrame
Title.Enabled = true
end)
Human.MouseEnter:Connect(function()
print("e")
if DB == false then
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.Human.CFrame
transition()
end
end)
Human.Activated:Connect(function()
print("the internal screaming is real")
if DB == false then
DB = true
TeamSetter:FireServer("Humans", Cams.Human)
Cam.CameraType = Enum.CameraType.Custom
Cam.CameraSubject = char.Humanoid
CloseEvent:Fire()
cas:UnbindAction("DisableControls")
end
end)
Vamp.MouseEnter:Connect(function()
print("i think this might be roblox's fault")
if DB == false then
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.Vampire.CFrame
transition()
end
end)
Vamp.Activated:Connect(function()
print("help")
if DB == false then
DB = true
TeamSetter:FireServer("Vampires", Cams.Vampire)
Cam.CameraType = Enum.CameraType.Custom
Cam.CameraSubject = char.Humanoid
CloseEvent:Fire()
cas:UnbindAction("DisableControls")
end
end)
Wolf.MouseEnter:Connect(function()
print("hey guys, it's markiplier")
if DB == false then
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.Werewolf.CFrame
transition()
end
end)
Wolf.Activated:Connect(function()
print("heloo")
if DB == false then
DB = true
TeamSetter:FireServer("Werewolves", Cams.Werewolf)
Cam.CameraType = Enum.CameraType.Custom
Cam.CameraSubject = char.Humanoid
CloseEvent:Fire()
cas:UnbindAction("DisableControls")
end
end)
Custom.Activated:Connect(function()
print("ey homeboy")
local fired = false
if DB == false then
print(DB)
DB = true
if fired == false then
CharEdit:Fire()
fired = true
end
print("fired")
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.CharEdit.CFrame
end
end)
Loaded.Event:Connect(function()
DB = false
end)
Custom.Activated:Connect(function()
print("ey homeboy")
local fired = false
if DB == false then
print(DB)
DB = true
if fired == false then
CharEdit:Fire("Custom.Activated")
fired = true
end
print("fired")
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = Cams.CharEdit.CFrame
end
end)
At this point, and for a lack of a better term, I am bamboozled, it looks like the function fires twice, even though the code fires it once, you might want to consider putting this topic to #bug-reports:studio-bugs.
I would, but unfortunately I don’t have access to making topics in bug reports… I joined after they closed the program that let devs get access to it. I’ll try flagging for a category change, though it’s unlikely to work.
I should mention, this all started happening after deleting Rojo (it was clogging up script analysis). I don’t know if that caused it. I’ll reinstall studio.
From the icon in this image, it appears that you are using Scripts with the RunContext set to Client. This means that they can run anywhere, even in StarterGui. The contents of StarterGui always exist, and they are cloned to the client’s PlayerGui upon loading into the game (or respawning, if the child is not a LayerCollector or has ResetOnSpawn enabled). Normally, this would not matter, as LocalScripts do not run in StarterGui. However, RunContext allows the Script to run anywhere, meaning that two copies of the script are running, one in StarterGui and one in the PlayerGui.
To get around this, you should always use LocalScripts in all ‘Starter’ containers, which is the recommended option in the announcement for RunContext.