So I am making a developer GUI and a part of it is the ability to lock the server. But when I test it studio freezes and then a few seconds later I get a game script timeout error. Not sure what I am doing wrong. Here are the various scripts that it uses:

The script that creates the BoolValue and kicks players when the value is true:

local serverlock = Instance.new("BoolValue", game:GetService("ReplicatedStorage"))
serverlock.Name = "lock"
serverlock.Value = false

serverlock.Changed:Connect(function()
	if serverlock.Value == true then
		while serverlock.Value == true do
			game.Players.PlayerAdded:Connect(function(plr)
				if plr:GetRankInGroup(5014306) >= 252 then
					print("non-kickable")
				else
				
				wait()
				
				plr:Kick("The server is locked.")
				end
			end)
		end
	end
end)

The OnServerEvent script that updates the value to true:

local storage = game:GetService("ReplicatedStorage")
local events = storage:WaitForChild("RemoteEvents")

events.ServerLockOn.OnServerEvent:Connect(function(player)
	storage.lock.Value = true
end)

The OnServerEvent script that updates the value to false:

local storage = game:GetService("ReplicatedStorage")
local events = storage:WaitForChild("RemoteEvents")

events.ServerLockOff.OnServerEvent:Connect(function(player)
	storage.lock.Value = false
end)

The FireServer script that causes the value to be updated to true:

script.Parent.MouseButton1Click:Connect(function()
	local storage = game:GetService("ReplicatedStorage")
	local events = storage:WaitForChild("RemoteEvents")
	
	events.ServerLockOn:FireServer()
	
	script.Parent.Parent.LockButton2.Position = UDim2.new(0.101, 0,0.806, 0)
	script.Parent.Position = UDim2.new(-1,0,0,0)
end)

The FireServer script that causes the value to be updated to false:

script.Parent.MouseButton1Click:Connect(function()
	local storage = game:GetService("ReplicatedStorage")
	local events = storage:WaitForChild("RemoteEvents")
	
	events.ServerLockOff:FireServer()
	
	script.Parent.Parent.LockButton1.Position = UDim2.new(0.101, 0,0.806, 0)
	script.Parent.Position = UDim2.new(-1,0,0,0)
end)

Those are all the scripts that the system uses. Any ideas?

1 comment

1

The game time out error is occurring because you have no wait on your while loop, without a wait things go south fast as your computer runs through an infinitely large number of calculations at once. So in your first code block add a wait() between lines 17 and 18.