Hello! I am trying to make my StarterCharacter move to one part to another using DevComputerMovementMode on scripted mode. How would I do this? Do note there are multiple parts shown here. The smallest parts are the path which the character would follow the big and medium parts the character would stop at. Factoring that in there are 14 parts the character would stop at.
So firstly you should disable their movement by running this locally, you could use a remote event
local ContextActionService = game:GetService("ContextActionService")
local FREEZE_ACTION = "freezeMovement"
ContextActionService:BindAction(
FREEZE_ACTION,
function() return Enum.ContextActionResult.Sink end,
false,
unpack(Enum.PlayerActions:GetEnumItems())
)
pcall(function()
local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule",10)):GetControls()
Controls:Disable()
end)
local UIS = game:GetService("UserInputService")
UIS.ModalEnabled = true
next in a ServerScript we must use pathfinding service to create a path to the part and then move the player’s character to it
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
local Character = Player.Character
local success, errorMessage = pcall(function()
path:ComputeAsync(Character.PrimaryPart.Position, destinationPart.Position)
end)
if success then
local waypoints = path:GetWaypoints()
local Humanoid = Character.Humanoid
for i,v in pairs(waypoints) do
Humanoid:MoveTo(v.Position)
if v.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
Humanoid.MoveToFinished:Wait()
end
else
print(errorMessage)
end
now when we want the player to walk on their own we run this on their client
ContextActionService:UnbindAction(FREEZE_ACTION)
pcall(function()
local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule",10))
local Controls = PlayerModule:GetControls()
Controls:Enable()
end)
local UIS = game:GetService("UserInputService")
UIS.ModalEnabled = false
1 Like
Sorry, but where would their client be? StarterCharacterScripts?
I also checked and got this error, It could be because I’m using a StarterCharacter but I’m not sure.
you must define the player. you want to move
starterplayerscripts and use remote events to tell it when to not allow the player to walk by themselves
Got it something like this?
… you must define the player you want to move. let say we want to move the player when they join
game.Players.PlayerAdded:Connect(function(Player)
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
local Character = Player.Character
local success, errorMessage = pcall(function()
path:ComputeAsync(Character.PrimaryPart.Position, destinationPart.Position)
end)
if success then
local waypoints = path:GetWaypoints()
local Humanoid = Character.Humanoid
for i,v in pairs(waypoints) do
Humanoid:MoveTo(v.Position)
if v.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
Humanoid.MoveToFinished:Wait()
end
else
print(errorMessage)
end
end)