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

How to make a server lock command and restrict only certain players to use it and be immune to it?

Someone answered my previous request, but they didn't really touch on what I wanted. Here's the script:

local SS = game.ServerStorage

game.Players.PlayerAdded:Connect(function(plr)
    local slocked = SS.Slocked
        slocked.Value = false   
        plr.Chatted:Connect(function(msg)
            if msg == "lockserver" and slocked.Value == false then
                    slocked.Value = true
                end

             if msg == "unlockserver" then
                    slocked.Value = false
             end

             if slocked.Value == true then
                        plr:Kick("The training center is closed! Please attend it at the scheduled time.")
                end
        end)
end)

1 answer

✓ Accepted answer

So you want certain players to run the command, and also want certain players to be immune. There is multiple ways to make certain players immune, I assume you have a group, so I'll use player:GetRankInGroup. You can use Player.UserId (or even Player.Name, however I do not suggest using this one.) Another thing I should say is that you should preset the BoolValue to false using the properties tab instead of setting the value via script.

local SS = game.ServerStorage

game.Players.PlayerAdded:Connect(function(plr)
	local slocked = SS.Slocked
	if slocked.Value == true then --Place it at the top and NOT under the Chatted event.
		if not plr:GetRankInGroup(0) == 255 then --If it's not the owner
			plr:Kick("The training center is closed! Please attend it at the scheduled time.")
		end
	end
	plr.Chatted:Connect(function(msg)
		if msg == "lockserver" and slocked.Value == false then
			if plr:GetRankInGroup(0) == 255 then --This is the owner rank. Replace the 0 with the groupID or just use the alternative mentioned.
				slocked.Value = true
			end
		end
		if msg == "unlockedserver" then
			if plr:GetRankInGroup(0) == 255 then
				slocked.Value = false
			end
		end
	end)
end)

1 comment

0

Thank you for helping me!

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