My script suddenly doesn't work after adding player control disabling/enabling

I wan’t my script to be functional and working. But it doesn’t work after firing a client with remote events. There was no errors too.


Server Script:

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local debounce1 = false
local debounce = false

local CollectionService = game:GetService("CollectionService")
local KillParts = CollectionService:GetTagged("KillPart")
local TeleportLobbyParts = CollectionService:GetTagged("TeleportLobbyPart")
local SpinParts = CollectionService:GetTagged("Spin")

-- Portal touching

workspace.Lobby.Portal.trigger.Touched:Connect(function(hit)
	local Randomchallenge = math.random(1, #ReplicatedStorage.RemoteEvents.Challenges:GetChildren())
	local RandomObby = math.random(1, #ServerStorage.Obbies:GetChildren())
	-- Delay
	if not debounce1 then
		debounce1 = true
		if hit.Parent:FindFirstChild("Humanoid") then
			
			local char = hit.Parent
			local plr = game.Players[char.Name]
			hit.Parent = char
			
			ReplicatedStorage.RemoteEvents.DisableControls:FireClient(plr)

			local Obby = plr:WaitForChild("stats").Obby
			local Challenge = plr:WaitForChild("stats").Challenge
			local Chances = plr:WaitForChild("stats").Chances

			Chances.Value = 3

			--Randomizing and getting the results in values

			Challenge.Value = ReplicatedStorage.RemoteEvents.Challenges:GetChildren()[Randomchallenge].Name
			Obby.Value = ServerStorage.Obbies:GetChildren()[RandomObby].Name

			-- Teleporting to the random obbies

			ServerStorage.Obbies:FindFirstChild(Obby.Value).Parent = workspace.Obbies
			
			ReplicatedStorage.RemoteEvents.TeleportTouched:FireClient(plr)
			char.HumanoidRootPart:PivotTo(workspace.Obbies:WaitForChild(Obby.Value).Teleport.CFrame)
			ReplicatedStorage.RemoteEvents.EnableControls:FireClient(plr)
			-- Running the challenges
			
			ReplicatedStorage.RemoteEvents.Challenges:FindFirstChild(Challenge.Value):FireClient(plr)
			wait(0.7)
			debounce1 = false
			
		end
	end
end)

Local Script:

local Controls = require(Player.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
ReplicatedStorage.RemoteEvents.DisableControls.OnClientEvent:Connect(function()
	Controls:Disable()
end)

ReplicatedStorage.RemoteEvents.EnableControls.OnClientEvent:Connect(function()
	Controls:Enable()
end)

Note: Those are the most important parts of the scripts.


Thanks a bunch!

if there is no errors, you should use prints. you should check the module scripts you are using as well

So I put the prints almost every 2nd line and didn’t got a single output.

try removing and adding back controls, maybe it’s not what causes the problem?

I removed

and

and it did work which is weird. But I need to disable and enable controls too.

so the problem is in the local script, maybe the player is nil?

Heres what I do for one of my games and it works, Im pretty sure Controls:Disable() doesn’t work on pc devices.

ReplicatedStorage.RemoteEvents.DisableControls.OnClientEvent:Connect(function()
	local FREEZE_ACTION = "freezeMovement"

	ContextActionService:BindAction(
		FREEZE_ACTION,
		function() return Enum.ContextActionResult.Sink end,
		false,
		unpack(Enum.PlayerActions:GetEnumItems())
	)


	pcall(function()
		local Controls =  require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule",10)):GetControls()
		Controls:Disable()
	end)

	local UIS = game:GetService("UserInputService")
	UIS.ModalEnabled = true
end)

ReplicatedStorage.RemoteEvents.EnableControls.OnClientEvent:Connect(function()
	local FREEZE_ACTION = "freezeMovement"
	ContextActionService:UnbindAction(FREEZE_ACTION)
	pcall(function()
		local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule",10))
		local Controls = PlayerModule:GetControls()
		Controls:Enable()
	end)

	local UIS = game:GetService("UserInputService")
	UIS.ModalEnabled = false
end)

So I tried doing the Controls:Enable() in server script too, and it just stops everything.

Would the problem be also storing the local script, because I inserted this into player scripts and it doesn’t work, neither the server script.

Edit: It works!