Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I keep a character from moving themselves, but still allow them to move via script?

Asked by 9 years ago

In case I was being vague, we want a player to not be able to control their character themselves, but a script will move them from point A to point B based on an event in the game. The event and the movement isn't the issue, the issue is that I don't know how to keep them from controlling their character ( since anchoring keeps us from using :MoveTo() )

1 answer

Log in to vote
2
Answered by 9 years ago

You can take away control from a player's character by removing the players Controller from the ControllerService.

ROBLOX basically links your character to the Controller object(s) in ControllerService. Removing the object(s) essentially blocks all keyboard input that could affect the character when using MoveTo.

You can find out how to do this here.

The script provided at the bottom of the wiki post has functions prepared that will add the controller objects to a table and then set their parent to nil and vice versa. It also has anonymous functions linked to the KeyUp and KeyDown events of the player's mouse.

The KeyDown event keeps a record of what buttons are pressed and sets the keyDown variable to true if there are any keys down, while the KeyUp event checks if all the buttons are false in the table and then sets the keyDown variable to what the result of the local hasKeyDown variable is.

The keyDown variable is checked when removing control of the character to check if no keys are being pressed before removing control to make sure you don't repeat your last action until character control is re-enabled.

I hope my answer helps you. If it did, be sure to accept it.

Ad

Answer this question