#Script running a function multiple times

22 messages · Page 1 of 1 (latest)

white mist
#

The bug I'm having with my script, is that if I press the skip button for however many times, the next time I press the equip button, it equips that amount of times. The same happens the other way around as well. Why does it loop even though both functions are outside of eachother?
(If more context is needed just lmk!)

tribal timber
#

because each spin it duplicates the function that the user didnt choose

#

for example i didnt want the element so i skipped it

#

but that just leaves the equipButton's Once method intact

#

so since the equipButton wasnt clicked, its connection to its equip Function will remain listening, waiting for the user's input

#

until its clicked

#

so you should store the two button connections to their own variables

#

like

local skipConnection = skipButton.MouseButton1Click:Once(function() blabla end)

#

then disconnect those 2 connections with the :Disconnect() method after firing either of the button functions to make it stop listening for the signal from the user's input, so like:

skipConnection:Disconnect()

white mist
#

Okay, that makes sense I'll try that, thank you!

white mist
tribal timber
#

yes yes

tribal timber
#

just initialize the variables first before assigning the functions to them

white mist
#

Works perfect now! Ty a ton

tribal timber
#

like

local skipConnection
local equipConnection

skipConnection = skipButton.MouseButton1Click:Once(function()
    --code yes
    --Disconnect methods here in the end
end)

equipConnection = skipButton.MouseButton1Click:Once(function()
    --code yes
    --Disconnect methods here in the end
end)

#

noice

white mist
#

Just curious, what are those variables storing exactly?

#

The function itself?

#

@tribal timber sorry for the ping, just wasn't sure if you had closed it

tribal timber
#

o mb

tribal timber