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

Can somebody help me? Cooldown script.

Asked by 10 years ago

Can somebody help me? I've been attempting to do this but it wont work. So I want a script so if you say "heal/", it will heal you, but if you say it too much it will cooldown. Does anyone know how to do that to prevent spam?

2 answers

Log in to vote
1
Answered by
3rdblox 30
10 years ago

Sorry, this site isn't for requesting scripts to be made for you.

0
That's not an answer. Wrongmistake 0 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

Never request scripts, by the way I am nice today: You can make a timer that start after the player chatted "heal/" like this:

local timer = 10 -- At how many seconds the timer will start
local timerStarted = false -- Has the time started?
function heal()
    -- Your heal code, inside it put this
    startTimer()
end

function startTimer()
    timerStarted = true
    while timer > 0 do
        timer = timer - 1
        wait(1) -- Wait 1 second before decrease the timer again, IT WILL NOT FINISH THE FUNCTION UNTIL THE LOOP HAS FINISHED!
    end
    timerStarted = false
    timer = 10 -- Resetting the timer, because the loop has finished
end

Ok we added something that checks if the timer Started or not, now we need to modify this:

function heal()
    -- Your heal code
    startTimer()
end

Into this

function heal()
    if timerStarted then
        stopSpam()
    else
        -- Your heal code
        startTimer()
    end
end

This simply check if the player healed while the timer has started or not, but we need to add the last and missing function: the stopSpam().... OOH it's sooooo hard! No joke:

function stopSpam()
    -- What will the game do to the player? Send a message? Create a gui? Or just banning him?
    print("A player used the 'heal/' command while his timer started!") -- Simply print to the output the error I wrote
end

The last thing is: you need to make sure that you call "heal()" inside the command function/script, example IN METALANGUAGE!:

if player chatted "heal/" then
    call stopSpam -- or just "stopSpam()"
end

It should work, the code hasn't been tested, PM me if you encounter any problem!

0
O_O That's confusing reading it all. Idk where to put all of that, do I just add it all together? Wrongmistake 0 — 10y
0
Yes, put those in one script, be careful and read the last thing paragraf alessandro112 161 — 10y

Answer this question