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

No clue why command is running twice?

Asked by 5 years ago
Edited 5 years ago

So I combined two admin scripts and I came up with a product, but it runs the command twice. No sure if it's the 4 am effects kicking in or this code being terrible. If anyone could help figure out why it's running twice that would be amazing.

Also I added in the "print("2 Print") to make sure it was doubling on the before the command ran.

local Admins = {
    "gage7252002"; -- Username example
    17614882; -- User ID example
    -- {GroupId = 0000;RankId = 255;} -- Group example
}


local Players = game:GetService("Players")


local function IsAdmin(Player)
    for _,Admin in pairs (Admins) do
        if type(Admin) == "string" and string.lower(Admin) == string.lower(Player.Name) then
            return true
        elseif type(Admin) == "number" and Admin == Player.UserId then
            return true
            elseif type(Admin) == "table" then
            local Rank = Player:GetRankInGroup(Admin.GroupId)
            if Rank >= (Admin.RankId or 1) then
                return true
            end
        end
    end
    return false
end




on=true
function onChatted(msg, recipient, speaker)
if string.lower(msg) == "3h" then
for i = 1, #Admins do
    print("2 Print")
if IsAdmin(speaker) then
    print("Added 3")
game.Workspace.GuiFolder.OneScore.Value = game.Workspace.GuiFolder.OneScore.Value +3
end
wait()
end
end
end












function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end

game.Players.ChildAdded:connect(onPlayerEntered)
0
Why are you using ChildAdded? You should be using PlayerAdded. User#19524 175 — 5y
0
Try to learn how to indent your code properly, to help with readability and understanding of code flow. In this case, your problem is that you're running lines 33-40 for the number of things in Admins. You have two things in Admins ' "gage7252002"; 17614882;', so it's gonna run for two times. Remove line 33 and an end. ScrewDeath 153 — 5y

Answer this question