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

Any explanation of why this script wont work?

I created a script, and It wont work, it has a spam limit, but the cooldown, wont work. Any explanation?

local spamlimit = 10000
local spamtime = 0.1
local cooldown = 5
local playerlist = {}

game.Players.PlayerAdded:connect(function(p)
p.Chatted:connect(function(msg)
if msg:lower() == "heal/" then
if playerlist[p] ~= true and (playerlist[p] == nil or playerlist[p][spamlimit] == nil or playerlist[p][spamlimit] - playerlist[p][1] >= spamtime) then
p.Character.Humanoid.Health = p.Character.Humanoid.MaxHealth
if playerlist[p] == nil then
playerlist[p] = {}
end
if playerlist[p][spamlimit] then
for i = 1, #spamlimit - 1 do
playerlist[p][i] = playerlist[p][i + 1]
end
playerlist[p][spamlimit] = tick()
else
table.insert(playerlist[p], tick())
end
elseif playerlist[p] ~= true then
playerlist[p] = true
Wait(cooldown)
playerlist[p] = nil
end
end
end)
end)

1 answer

What is the output? The only way you can test these is to go in a local server with a player or publish it and play the place.

Here is the change I made: (I tabbed it and made a few edits)

local spamlimit = 10000
local spamtime = 0.1
local cooldown = 5
local playerlist = {}

game.Players.PlayerAdded:connect(function(p)
    p.Chatted:connect(function(msg)
        if msg:lower() == "heal/" then
            if (playerlist[p.Name] == false or playerlist[p.Name] == nil) and (playerlist[p.Name] == nil or playerlist[p.Name][spamlimit] == nil or playerlist[p.Name][spamlimit] - playerlist[p.Name][1] >= spamtime) then
                p.Character.Humanoid.Health = p.Character.Humanoid.MaxHealth

                if playerlist[p.Name] == nil then
                    playerlist[p.Name] = {}
                end

                if playerlist[p.Name][spamlimit] then
                    for i = 1, spamlimit - 1 do
                        playerlist[p.Name][i] = playerlist[p.Name][i + 1]
                    end

                    playerlist[p.Name][spamlimit] = tick()
                else
                    table.insert(playerlist[p.Name], tick())
                end
            elseif playerlist[p.Name] ~= true then
                playerlist[p.Name] = true
                wait(cooldown)
                playerlist[p.Name] = nil
            end
        end
    end)
end)

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