Studio Lags After Enabling Back Player Controls

Hello Developers!
I’m making a cutscene for one of my new projects. I have added a script that disables Player Controls through a remote function from a server script but after Enabling back Controls through another separate Remote Function Roblox Studio Lags
Here is the script

local PlayerMod = require(game:GetService("Players").LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerMod:GetControls()
local ToggleDisables = game.ReplicatedStorage.RemoteEvents.ToggleEvents.ToggglePlayerDisablesEvent
local UnToggleDisables = game.ReplicatedStorage.RemoteEvents.ToggleEvents.UnToggglePlayerDisablesEvent


local function ControlsOff()
	Controls:Disable()
end

local function ControlsOn()
	Controls:Enable()
end




ToggleDisables.OnClientEvent:Connect(ControlsOff)
UnToggleDisables.OnClientEvent:Connect(ControlsOn)

After Enabling back Player Controls I get this error

   ▶ Maximum event re-entrancy depth exceeded for Instance.Changed (x4144)  -  

If anyone has a solution or another method for disabling player controls that would be greatly appreciated thanks for reading!

1 Like

There’s a changed event that hasn’t been included in your code block that has an infinite loop. Something like

local NumberValue = script.NumberValue

local function valueChanged()
  NumberValue.Value += 1
end

NumberValue.Changed:Connect(valueChanged)

something like this would cause this error as it creates an infinite loop which roblox then breaks with that custom error message as the changed event is fired when the value is changed and then the function that is connected to that event changes the value running the function again and again and again…

are you sure the error in the console is coming from that script?

1 Like

Yep You are correct! The error was coming from an older script I had forgot to Discard Thank you for the help! The old script was also relying on the ToggleEvents So thats why I suspected that it was The Disable Player Controls Thank you again! :smiley:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.