Slock System Bugs

I have attempted to make a slock command, however it doesn’t kick the player. Could anyone help out a bit?

local GroupId = 13240359 --REPLACE 12345 WITH YOUR GROUP ID
local MinimumRankToUseCommands = 247 --REPLACE 254 WITH THE MINIMUM RANK ID TO USE THE SLOCK AND UNSLOCK COMMANDS
local MinimumRankToJoinSlocked = 247 --REPLACE 10 WITH THE MINIMUM RANK ID PLAYERS HAVE TO BE IN ORDER TO JOIN WHEN THE SERVER IS LOCKED
local ServerLockMessage = "------------ACTIVE TRAINING------------ \n \n An training is currently active/ongoing meaning you can't join at this moment! Please join again later. \n \n [NOTE] Have you happened to disconnect or needed to rejoin without telling the host? If so, please DM the host or wait, if not, please wait until the next training." --REPLACE THE TEXT INSIDE OF THE "" WITH YOUR SERVER LOCK MESSAGE

local ServerLocked = false

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommands then
			if Message == ".lock" then
				ServerLocked == true
				
				local Players = game.Players.LocalPlayer
				
				for i = 1, #Players do
					local CurrentPlayer = Players[i]
					local ServerLockMessage = Player.PlayerGui.ServerLockGUI.ServerLockMessage
					
					ServerLockMessage.Visible = true
					ServerLockMessage.Text = Player.Name.. " has locked the server!"
					wait(5)
					ServerLockMessage.Visible = false
				end
				
			elseif Message == ".unlock" then
				ServerLocked == false
				
				local Players = game.Players.LocalPlayer
				
				for i = 1, #Players do
					local CurrentPlayer = Players[i]
					local ServerLockMessage = Player.PlayerGui.ServerLockGUI.ServerLockMessage
					
					ServerLockMessage.Visible = true
					ServerLockMessage.Text = Player.Name.. " has unlocked the server!"
					wait(5)
					ServerLockMessage.Visible = false
				end
			end
		end
	end)
	
	if ServerLocked == true then
		if Player:GetRankInGroup(GroupId) < MinimumRankToJoinSlocked then
			Player:Kick(ServerLockMessage)
		end
	end
end)

Thanks

Have you printed their group rank to see what it prints? Or if it even has set ServerLocked false? It could be a logical error where values aren’t what you think they should be.