Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
7

Equipped and Unequipped event being called repeatedly?

Asked by 11 years ago

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...

01--Here are two things you should know.
02--All variables are defined.
03--newweld() is a welding function that works 100%.
04--The problem is ONLY the equipped/unequipped events being called multiple times.
05 
06function weldarms()
07    local copygun = game.ServerStorage.Remi700:Clone()
08    copygun.Parent = tool
09    gun = copygun:GetChildren()
10    for i, v in ipairs(gun) do
11        v.Parent = copygun.Parent
12    end
13    copygun:Destroy()
14    newweld(Handle, tool.reciever, tool.reciever, "gunweld")
15    player.Torso:findFirstChild("Left Shoulder").Part1 = nil
View all 22 lines...

3 answers

Log in to vote
0
Answered by
Kozero 120
11 years ago

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

0
Use Debounce or wait like @Kozero said PlayableReviews 0 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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.

Log in to vote
0
Answered by 7 years ago

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.

Answer this question