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?
Sorry, this site isn't for requesting scripts to be made for you.
Never request scripts, by the way I am nice today: You can make a timer that start after the player chatted "heal/" like this:
01 | local timer = 10 -- At how many seconds the timer will start |
02 | local timerStarted = false -- Has the time started? |
03 | function heal() |
04 | -- Your heal code, inside it put this |
05 | startTimer() |
06 | end |
07 |
08 | function startTimer() |
09 | timerStarted = true |
10 | while timer > 0 do |
11 | timer = timer - 1 |
12 | wait( 1 ) -- Wait 1 second before decrease the timer again, IT WILL NOT FINISH THE FUNCTION UNTIL THE LOOP HAS FINISHED! |
13 | end |
14 | timerStarted = false |
15 | timer = 10 -- Resetting the timer, because the loop has finished |
16 | end |
Ok we added something that checks if the timer Started or not, now we need to modify this:
1 | function heal() |
2 | -- Your heal code |
3 | startTimer() |
4 | end |
Into this
1 | function heal() |
2 | if timerStarted then |
3 | stopSpam() |
4 | else |
5 | -- Your heal code |
6 | startTimer() |
7 | end |
8 | 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:
1 | function stopSpam() |
2 | -- What will the game do to the player? Send a message? Create a gui? Or just banning him? |
3 | print ( "A player used the 'heal/' command while his timer started!" ) -- Simply print to the output the error I wrote |
4 | end |
The last thing is: you need to make sure that you call "heal()" inside the command function/script, example IN METALANGUAGE!:
1 | if player chatted "heal/" then |
2 | call stopSpam -- or just "stopSpam()" |
3 | end |
It should work, the code hasn't been tested, PM me if you encounter any problem!