Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Equipped and Unequipped event being called repeatedly?

Lately I've been forced to use debounce in my tools because for some reason, the tool calls a function connected to the Equipped/Unequipped event like a thousand times. I thought it was supposed to be called only once.

Should this be happening? Or is this an error on Roblox's side?

Here is part of the script. I kinda don't think it's something I did in the script though.

Edit1: It seems like it ONLY occurs on this tool. I just tried another tool, and it didn't excessivley call the function like this tool did.

Edit2: I think I found the source of the problem. When I cloned Remi700 from ServerStorage, it glitches the entire script. Roblox bug?

Edit3: It seemed to solve the problem when I put a wait() in there. I still don't know why this happened...

--Here are two things you should know.
--All variables are defined.
--newweld() is a welding function that works 100%.
--The problem is ONLY the equipped/unequipped events being called multiple times.

function weldarms()
	local copygun = game.ServerStorage.Remi700:Clone()
	copygun.Parent = tool
	gun = copygun:GetChildren()
	for i, v in ipairs(gun) do
		v.Parent = copygun.Parent
	end
	copygun:Destroy()
	newweld(Handle, tool.reciever, tool.reciever, "gunweld")
	player.Torso:findFirstChild("Left Shoulder").Part1 = nil
	player.Torso:findFirstChild("Right Shoulder").Part1 = nil
	newweld(tool.Parent.Torso, player:findFirstChild("Right Arm"), player:findFirstChild("Torso"), "rarmweld")
	tool.Parent.Torso.rarmweld.C1 = CFrame.new(1,.4,-.3)*CFrame.Angles(math.pi/2,0,6.3)
	newweld(tool.Parent.Torso, player:findFirstChild("Left Arm"), player:findFirstChild("Torso"), "larmweld")
	tool.Parent.Torso.larmweld.C1 = CFrame.new(0,.48,-1)*CFrame.Angles(math.pi/2,-.1,7)
end
tool.Equipped:connect(Weld)

3 answers

Make sure you use Debounce or wait() to stop it from overlapping the executing of your function .

1 comment

0

Use Debounce or wait like @Kozero said

When using Equipped it is always essential to use debounce, BUT it is EXTREMELY important to reset the debounce in the right place. So if you are using an if Statement then you would put it afterward. I cannot stress this enough. Debounce is a very useful code for these kinds of scripts. I would recommend using the debounce right after the function is called and right before it ends.

If you use debounce() it will help. Click here for a YouTube tutorial on debounces. Otherwise use the ROBLOX Developer Wiki's article by clicking here.

Click here for the ROBLOX Blog.

Click here for the ROBLOX Developer Wiki.

This discussion is preserved as it was. New answers, comments, and votes are closed.