Disable controls, still move character via script?

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?

Thanks in advance!
Jonas

3 Likes

this thread might have your sollution.

Controlscript changed :expressionless: Riperonni. Aka, out to date. Still thanks, though!

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.

1 Like

Thanks! That did the trick. :smiley:

2 Likes

Hey, I just wanted to point out that it’s usually polite to mark the solution as the person who actually solved the issue :slight_smile:

4 Likes

Oh, I thought I did. Anyway, did it now. Thanks for reminding me!

3 Likes