I already did setup a RemoteEvent and a pretty basic script, but i got stuck at the pathfinding part.
Server Script:
--Variables
local PathFindingService = game:GetService("PathfindingService")
local ReplicatedStorage = game.ReplicatedStorage
local RemoteEvent = ReplicatedStorage.RemoteEvents.Units.UnitMove
--//Move Unit to Province
local function MoveUnit(Player, TAG, Target, Units)
end
RemoteEvent.OnServerEvent:Connect(MoveUnit)
Client Script:
--Variables
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player.GetMouse()
local TAG = Player.TAG
local ReplicateStorage = game.ReplicatedStorage
local RemoteEvent = ReplicateStorage.RemoteEvents.Units.UnitMove
--Script
--//Call RemoteEvent When Right Click
local function RightClick(Player)
local Target = Mouse.Target
for i,v in pairs(game.Workspace.Units:GetChildren()) do
if v.Info.isSelected == true then
RemoteEvent:FireServer(TAG.Value ,Target, v)
end
end
end
Mouse.Button2Down:Connect(RightClick)
I would start here: Character Pathfinding | Documentation - Roblox Creator Hub. If I see it correctly, it maybe will be more problematic since your world is 2D (or is it 3D?) and - as far as I know - Roblox’s pathfinding is working in 3D. It could be fixed by just placing the map horizontally on the world (if that’s not already the case). But I guess more info on where exactly you’re stuck would be useful, except if you expect someone will now just script this whole thing
Infact my map is 3D, it’s just the position i took the Screenshot.
I managed to do a simple pathfinding script and it works like a charm.
Script:
--Variables
local PathFindingService = game:GetService("PathfindingService")
local Path = PathFindingService:CreatePath()
local ReplicatedStorage = game.ReplicatedStorage
local RemoteEvent = ReplicatedStorage.RemoteEvents.Units.UnitMove
--Script
--//Move Unit to Province
local function MoveUnit(Player, TAG, Target, Units)
print("Start")
Path:ComputeAsync(Units.UnitModel.PrimaryPart.Position, Target.Position)
local Humanoid = Units.UnitModel:WaitForChild("Humanoid")
local Waypoints = Path:GetWaypoints()
for i, Waypoints in pairs(Waypoints) do
Humanoid:MoveTo(Waypoints.Position)
Humanoid.MoveToFinished:Wait(1)
end
print("Done?")
end
--//RemoteEvent
RemoteEvent.OnServerEvent:Connect(MoveUnit)
But the question now is that my units move smoothly from one point to another, but i want them to teleport after a certain amount of time, i tried to just do:
PrimaryPart.Position = Waypoint.Position
But it didn’t work. So how can i achieve that?