Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to add a cool down to chat command?

So this script here allows you to say !Explode and creates an explosion but you can spam it. Is there any way to stop this?

function onChatted(msg, speaker)
source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "!explode" then
local boom = Instance.new("Explosion")
boom.Parent = game.Workspace
boom.Position = speaker.Character.UpperTorso.Position
boom.BlastPressure = 5
boom.BlastRadius = 10
end
end
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg) onChatted(msg, newPlayer) end) 
end
game.Players.ChildAdded:connect(onPlayerEntered)

2 answers

✓ Accepted answer

I'm not exactly sure if you want it so you can't use it when you're dead or if you just want a cooldown, so I'll try my best to do both.

(Note: My method for making cooldowns is really bad, but my bad method works for this because the cooldown will atleast work on everyone.)

Can't explode on death:

-- this should work. i didnt test it though so im hoping it does work
function onChatted(msg, speaker)
source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "!explode" then
local human = speaker.Character.Humanoid
if human.Health > 0 then
local boom = Instance.new("Explosion")
boom.Parent = game.Workspace
boom.Position = speaker.Character.UpperTorso.Position
boom.BlastPressure = 5
boom.BlastRadius = 10
end
end
end
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg) onChatted(msg, newPlayer) end) 
end
game.Players.ChildAdded:connect(onPlayerEntered)

Cooldown for explosion (not just can't explode when dead):

-- hoping this also works
function onChatted(msg, speaker)
source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "!explode" and not speaker.Character:FindFirstChild("debounceBoom") then

local value = Instance.new("NumberValue", speaker.Character) -- i use numbervalues since the time the debounce lasts for is the value
value.Name = "debounceBoom"
value.Value = 2 -- change to whatever u want
game:service("Debris"):AddItem(value, value.Value)

local boom = Instance.new("Explosion")
boom.Parent = game.Workspace
boom.Position = speaker.Character.UpperTorso.Position
boom.BlastPressure = 5
boom.BlastRadius = 10
end
end
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg) onChatted(msg, newPlayer) end) 
end
game.Players.ChildAdded:connect(onPlayerEntered)

Hopefully any of these 2 work for you. :)

2 comments

0

tysm i tried looking on the roblox website to see if i could try but couldnt so i truly thank you

0

you're welcome

This discussion is preserved as it was. New answers, comments, and votes are closed.