I want to end the script if cooldown is set to true but I’ve used return but when I use that it repeats the function itself, how would I go about doing this? Basically i want to make so the script does not continue to the code below if cooldown is true
if Cooldown.Value==true then
-- i want to end the script here if cooldown is true
else
CooldownTimer(EntityCharacter, CooldownName)
end
What is the triggering event for this code? (e.g. heartbeat, renderstepped, etc)
Return is likely what you are looking for, but if the code runs again something else is doing it.
["Down"] = function(Data)
local EntityCharacter = Data.EntityCharacter
local Cooldown = Data.EntityCharacter.Cooldown:FindFirstChild("Red Stomp")
local CooldownName = "Red Stomp"
if Cooldown.Value==true then
return
else
CooldownTimer(EntityCharacter, CooldownName)
end
return should do it, but if Cooldown returns nil it would run the else code.
Also, if it is being triggered from user input button down and button up will create two events.
Can you send the rest of your code? It’s kind of hard to understand what’s going on when all we get is this snippet.
What I’d imagine is going on is somewhere if your code there’s a loop calling the “Down” function, so returning early just causes the function to be called again on the next loop.
If you’re looking to break out of the loop completely there’s a few ways of doing this off the top of my head that includes setting a global boolean, erroring instead of returning, or yielding the thread.
No.
return by itself is returning nil
return nil is also returning nil
Both would return nil to the function that called it, and normally would exit the function running (so in this case RedStomp.Down)
What I meant was if the findfirstchild failed it would set cooldown as nil, thus triggering the ‘else’ part of the code.
See, @yellp1 's post, the return value probably isn’t the issue here.
A minor correction; If the FindFirstChild returned nil, or an object that wasn’t a BoolValue, it would just error rather than run the else code.
Totally see what you’re were getting at here though!
i fixed the issue of it repeating itself but now I want to make so the code is actually able to run again when its use because players press V to toggle it, but now when the cooldown is true and the return statement is used the code dosent work again
ive used a return but I want the script to be able to be repeated again when a player presses a key, when I use return it terminates the whole entire script