Help: Upon holding tool, player is forced to walk forwards for 4 seconds

How would I write a script that makes the player walk forwards once they’ve equipped the tool for like 4 seconds? I want it to be like an ability so it’s like

  1. The tool is equipped
  2. The script in the tool fires, making the player who equipped the tool lose control of their movement and be forced to walk forwards for 4 seconds and then it stops, so the player is free to do whatever they want afterwards again.
  3. There is a cooldown so you can’t spam this ability
    (If the tool is unequipped when the ability is in the middle of it’s function, it shouldn’t stop the walking)

Steps 1 and 3 I can do myself, all I’m asking for is some pointers!

You can get the player movement module, and then call :Disable() on it, then just keep calling
humanoid:WalkToPoint(hrp.CFrame.Position + hrp.CFrame.LookVector)
for 4 seconds,
or
humanoid:WalkToPoint(hrp.CFrame.Position + hrp.CFrame.LookVector * 100)
And after 4 seconds
humanoid:WalkToPoint(hrp.CFrame.Position) (to stop it from walking there)

and once the 4 seconds are up, just call :Enable(), and for the cooldown you can just save the time it was last used (and 0 at the start) and check if os.time() - lastUsed >= cooldown

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.