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)
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. :)