Hello! I am trying to make a script where the player automatically follows a path. The player should not be able to control the charachter him/her self.
I got this script:
local ToggleCharControl = game.ReplicatedStorage:WaitForChild("CharControl")
ToggleCharControl.OnClientEvent:connect(function(state)
local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
-- In order to access controls, you must first get the controls
local Controls = PlayerModule:GetControls()
if not state then
Controls:Disable()
else
Controls:Enable()
end
--game.Players.LocalPlayer.PlayerScripts.ControlScript.Disabled = not state
end)
That is client sided, enabling and disabling the controls.
On my server script, I do humanoid:MoveTo(part.Position). It does perfectly work when I do not disable the controls, but when I do, it doesn’t.
Is there a way to make the character move via a script and making the player unable to interrupt it?
I would create a custom ControlScript and get ContextActionService, then I would use :BindAction and :UnbindAction to dictate when your controls are useable.
Actions configured through ContextActionService can use several keys, and you can also differentiate between them through the InputObject that is passed to the function. Therefore, you could pin the entire control scheme under an action and unbind/bind it with a single string.