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

Admin commands working in studio but not in game?

Asked by 4 years ago

I'm making custom admin for my game but it only works in studio.

Here is my script.

local Admins = {"ScriptToon"}
for i,v in pairs(Admins) do
    game.Players[Admins[i]].Chatted:Connect(function(msg)
        if msg == "Script-KickAll" then
            local players = game.Players:GetPlayers()
            for p = 1,#players do
                players[p]:Kick("You were kicked by an admin!")
            end
        end
    end)
end
0
Sorry for the inconvenience, this question did fall within our guidelines and was moderated by a member of the community. After review, the question has been restored and reputation has been reallocated to your account to make up for the loss. M39a9am3R 3210 — 4y

1 answer

Log in to vote
0
Answered by
compUcomp 417 Moderation Voter
4 years ago

That code assumes that the player is already there when the server is created. Fix:

local Admins = {"ScriptToon"}
game.Players.PlayerAdded:Connect(function(p)
    for i, v in pairs(Admins) do
        if v == p.Name then
            p:Connect(function(msg)
                if msg == "Script-KickAll" then
                local players = game.Players:GetPlayers()
                for p = 1,#players do
                    players[p]:Kick("You were kicked by an admin!")
                end
            end)
        end
    end
end)

0
Had to make a tweak but it works perfectly! thanks! ScriptToon 70 — 4y
0
Glad I could help :D compUcomp 417 — 4y
Ad

Answer this question