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

Problem with these 2 admin commands?

Asked by 9 years ago

I have these 2 admin commands I made a few hours ago.

Let me show you the first one, which is a command list (BTW, the script is in the GUI that I am cloning):

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)
        if msg == ":cmds" then
            local clone = script.Parent:clone()
            clone.Parent = plr.PlayerGui
        end
    end)
end)

And my second one is an infinite gold command:

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)
        if msg == ":InfGold" and plr.Name == "groovydino" or plr.Name == "Player" or plr.Name == "dragonmaster4111" or plr.Name == "LimitedGoneWrong" then

            local stats = plr:FindFirstChild("leaderstats")
            if stats ~= nil then
                local gold = stats:FindFirstChild("Gold")
                if gold ~= nil then
                    gold.Value = 999999999
                end
            end

        end
    end)
end)

The problem is, if I say :cmds (referring to the first script) the command list GUI does pop up, but for some reason, I get infinite gold, too. And I didn't even say :InfGold! What is the problem here and how can I fix it?

0
Don't use two PlayerAdded events, just combine them bot into one. Perci1 4988 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

Your problem was with the second command. When you checked to see if the player was an admin, you used "or" without imbedding it in an "and". This means that if the player's name is equal to any name other than the first name statted, it will give them infinite gold anyways. To fix this, just put an open parenthesis after "and" and a closed parentheses before "then". However, we can make the script more efficient using a for loop to check if the player is an admin. Here's the finished script:

First Command:

PlayerAdded:connect(function(player)
PlayerChatted:connect(function(msg)
if msg == ":cmds" then --If you don't want this to be case--sensitive, then you can change this line to *if string.lower(msg) == ":cmds" then*
local clone = script.Parent:Clone()
clone.Parent = player.PlayerGui
end
end)
end)

Second Command:

local admins = {"Player", "Player1", "dragonmaster4111", "LimitedGoneWrong", "groovydino", "aquathorn321"}

game.Players.PlayerAddded:connect(function(player)
for i,v in pairs(admins) do
if v == player.Name then
player.Chatted:connect(function(msg)
if msg ==":InfGold" then --If you don't want this to be case-sensitive, then you can change this line to *if string.lower(msg) == ":infgold" then*
local stats = player:FindFIrstChild("leaderstats") --We don't need if statements checking to see if stats or gold exists, because the code will return an error and stop running on its own.
local gold = stats:FindFirstChild("Gold")
gold.Value == 999999999
end
end
break --end the loop if the player is recognized as an admin
end
end
end)
0
Thanks for the answer, and the addition of the other stuff being fixed. I accepted your answer and added an upvote. groovydino 2 — 9y
0
But does it make sure I dont get infinite gold when i say :cmds? groovydino 2 — 9y
0
Never mind, I already tested it and it works. groovydino 2 — 9y
0
No problem aquathorn321 858 — 9y
Ad

Answer this question