This is my second post of the day and probably is the last thing ill need help with.
alright so I have two scripts and I need to pass info between both of these scripts using bindable events before activating the tool, but when firing then activating the tool it starts activating multiple times depending on how many times the bindable event was fired, here’s an image of the output
you can see everything was working as expected until the gun was activated twice resulting in it activating 4 times times when used again
here are both scripts (only the relevant parts)
script1:
TimerEndedBindable.Event:Connect(function(Player1, Player2, Room, v)
print("TimerEndedBindable Recieved from TVRESULT SCRIPT")
-- some irrelevant stuff are between these two lines
GunEquippedBindable:Fire(Player1, Player2, Room, v, BackPack)
print("GunEquippedBindable Fired")
-- the script continues
script2:
GunEquippedBindable.Event:Connect(function(Player1, Player2, Room, v, BackPack)
print("Bindable Event Recieved")
-- some irrelevant stuff between these two lines
Gun.Activated:Connect(function()
print("Gun Activated")
-- the script continues
I tried stopping it from firing the bindable event after firing once and this fixed it but it’s not updating the info needed for the gun to be activated resulting in a whole bunch of bugs so the issue lies here.
how can I stop this from happening? reminder I can’t prevent the event from firing again after the first time, it must keep on firing each time before the gun is activated to update the passed data.
The problem is you’re connecting the event multiple times, so, when you activate the gun once, all those connections that are listening get fired. Can you specify what type of data needs to be updated for each fire? To fix the problem you’ll probably need to take the connection out of the bindable’s listener and transfer the data through variables or another creative way.
That may be kind of hacky, but for that purpose you can disconnect the bindable’s listener:
local Connection = Bindable.Event:Connect(function()
-- code
end)
Connection:Disconnect() -- Disconnect
or stop the code after activated once while maintaining the connection:
local FiredOnce = false
Bindable.Event:Connect(function()
-- important code
if FiredOnce then return end
FiredOnce = true
-- code that you want not to run after the first activation
end)
alright I tried your Disconnect() method, this fixed the tool but now I’m back to the original error I had before
I tested the game with my alt and as you can see it printed the data I need once, indicating that it’s not updating it, and that it’s not firing the bindable event again.
I don’t have much experience but I’m rather sure you can use :Once() instead of :Connect() for the Gun.Activated since you’re not gonna need that connection after it fires. This way it would run once, as the name implies, and automatically disconnect after being fired.