This in general is really bad practice, putting events under while loops. And creating new while loop each time an event fires. This will create a big mess. This can be simplified soo much.
Also you don’t need to store the value in a value object, just have a variable in the script indicating wether you lock or not. And also, don’t make two remote events one for each button to change the value, just make one, and each time a button is clicked fire the same remote passing wether true or flase.
local lock = false
game.ReplicatedStorage.slock.OnServerEvent:Connect(function(plr, val)
lock = val
end)
game.Players.PlayerAdded:Connect(function(plr)
if lock then
plr:Kick("Server Locked")
end
end)
This might help as well.