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

How to do this to make my admin commands better?

Asked by 9 years ago

I have some admin commands, but I only need to show you 1 for this problem:

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)

    if msg == ":InfGold" and plr.Name == "Player" or plr.Name == "dragonmaster4111" or plr.Name =="LimitedGoneWrong" or plr.Name == "groovydino" 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)

On line 4, is there any way I can change that to make it better? And I am NOT sure about this, but I think line 4 has a problem with the "or" part. Help?

0
@groovy, you can make it math.huge. If it's math.huge it will say "inf" not -28465.57364 or anything. Can you leave me on the admin list *hint hint*. BTW please accept my answer. EzraNehemiah_TF2 3552 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

Add a table with all the names and instead of doing gold.Value = 99999999999 do gold.Value = math.huge. Math.huge is basically infinity.

admin = {"Player", "Player1", "dragonmaster4111", "LimitedGoneWrong", "groovydino", "LordDragonZord"}

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)

    for _,adminname in pairs(admin) do
            if msg == ":InfGold" and  plr.Name == adminname then
                          local stats = plr:FindFirstChild("leaderstats")
                          if stats ~= nil then
                             local gold = stats:FindFirstChild("Gold")
                             if gold ~= nil then
                                gold.Value = math.huge
                                end
                            end
            end
        end
        end)
end)

Hope it helps!

0
Dude, I put it on 999,999,999 because if it goes beyond 999,999,999 then the value of the gold becomes -2147483648. Thanks for the answer anyway! (And I saw the admin table :3) groovydino 2 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

A much more efficient way to do this would be to run the for loop in PlayerAdded so that we do not run a for loop every time we want to process a message. This will reduce a lot of lag depending on the length of your admin list.

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)

Answer this question