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

Admin commands working in studio but not in game?

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

1 comment

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.

1 answer

✓ Accepted answer

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)

2 comments

0

Had to make a tweak but it works perfectly! thanks!

0

Glad I could help :D

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