I wrote this script that when you click a button, it says you own the room, and nobody else can take it until you check out. When you click check out, it says nobody owns the room anymore and other people can claim it. This works in studio, however it doesn't work in game or local server test. What happens is you can check in once and then check out once, but after that when you try to check in again a second time, it says you own it for a split second, before it says nobody owns it again. This happens every time you try to claim it after the second try. Here are my scripts:
-- client side taken = false local function OnClick() if taken == false then script.Parent.TakenBy.Text = "Taken by "..game.Players.LocalPlayer.Name.."!" game.StarterGui.Rooms.Frame.Room1.TakenBy.Text = "Taken by "..game.Players.LocalPlayer.Name.."!" game.Workspace.Room1:FireServer("CheckIn") taken = true end end script.Parent.MouseButton1Click:Connect(OnClick) game.StarterGui.Room1.OnClientEvent:Connect(function(plr,thing) if thing == "CheckIn" then print("Client received") script.Parent.TakenBy.Text = "Taken by "..plr.Name.."!" game.StarterGui.Rooms.Frame.Room1.TakenBy.Text = "Taken by "..plr.Name.."!" taken = true elseif thing == "CheckOut" then script.Parent.TakenBy.Text = "Taken by nobody!" game.StarterGui.Rooms.Frame.Room1.TakenBy.Text = "Taken by nobody!" game.Workspace.Room1:FireServer "CheckOut" taken = false end end) script.Parent.Parent.Checkout.MouseButton1Click:Connect(function() script.Parent.TakenBy.Text = "Taken by nobody!" game.StarterGui.Rooms.Frame.Room1.TakenBy.Text = "Taken by nobody!" game.Workspace.Room1:FireServer"CheckOut" taken = false end)
.
-- server side game.Workspace.Room1.OnServerEvent:Connect(function(player,thing) if thing == "CheckIn" then game.StarterGui.Room1:FireAllClients(player,"CheckIn") print("server received") elseif thing == "CheckOut" then game.StarterGui.Room1:FireAllClients(player,"CheckOut") end end)
In the output it says: 20:23:27.678 - Maximum event re-entrancy depth exceeded for RemoteEvent.OnServerEvent
and 20:23:27.679 - While entering function defined in script 'ServerScriptService.Room1', line 1
I don't even understand what that means. The game is FE btw. Help is appreciated.
You have an infinite loop when checking out.
When you checkout it fires
game.Workspace.Room1:FireServer"CheckOut" --Line 32
Which then fires this code in the server side script
game.StarterGui.Room1:FireAllClients(player,"CheckOut") --Line 7
Which then fires this code in the client side
game.Workspace.Room1:FireServer"CheckOut" --Line 24
Which would go on forever...
The error you get is caused when to many events are being fired in a short amount of time. Which would be caused by this infinite loop.
Im also assuming you have parenthesis around "CheckOut"
So get rid of line 24 in client side and see if that works.