I’m currently working on an unicycle vehicle and I need all player controls disabled. The function that disables it was working fine until a few hours ago, until it randomly decided to stop working without making any changes to the script or anything else. I tried to recreate this and disabled all scripts and added a script to test with the following in it:
local function Setup()
require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
game:GetService("ContextActionService"):UnbindAction("jumpAction")
game:GetService("ContextActionService"):UnbindAction("moveForwardAction")
game:GetService("ContextActionService"):UnbindAction("moveBackwardAction")
game:GetService("ContextActionService"):UnbindAction("moveLeftAction")
game:GetService("ContextActionService"):UnbindAction("moveRightAction")
end
Setup()
…and sure enough it was not working. What should I do?
Remove the prints, and the controls Enable, its only there for demonstration, also move the variables above the function
local function Setup()
print("yo")
local ControlScript = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = ControlScript:GetControls()
Controls:Enable() -- enable the controls whenever you want
Controls:Disable() -- disable the controls whenever you want
game:GetService("ContextActionService"):UnbindAction("jumpAction")
game:GetService("ContextActionService"):UnbindAction("moveForwardAction")
game:GetService("ContextActionService"):UnbindAction("moveBackwardAction")
game:GetService("ContextActionService"):UnbindAction("moveLeftAction")
game:GetService("ContextActionService"):UnbindAction("moveRightAction")
print("worked")
end
Setup()
print("called")
I else got no idea then, i changed one thing with an if statement so try using that
local ControlScript = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = ControlScript:GetControls()
local player = game.Players.LocalPlayer
local ContextActionService = game:GetService("ContextActionService")
local function Setup()
if player then
print("yo")
Controls:Disable() -- disable the controls whenever you want
ContextActionService:UnbindAction("jumpAction")
ContextActionService:UnbindAction("moveForwardAction")
ContextActionService:UnbindAction("moveBackwardAction")
ContextActionService:UnbindAction("moveLeftAction")
ContextActionService:UnbindAction("moveRightAction")
print("worked")
end
end
Setup()