Hey,
Alright so I think I got something to work, instead of working with Vector3 values I just decided to completely work with CFrame values instead because, reasons
Point is, I seem to be encountering an issue now, the “enemy part” is tweening its value from where it is to the node and once it arrives at the node it just stops counting, for some reason it doesn’t continue to the next node.
Here’s the code so far:
(Server Side Code)
wait(5)
local TS = game:GetService("TweenService")
local test = game.ReplicatedStorage:WaitForChild("Spawned")
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
for _, npc in ipairs(game.Workspace.Mobs:GetChildren()) do
--On enemy spawn
task.spawn(function()
for _, GoalNode in ipairs(game.Workspace.Nodes:GetChildren()) do
local Distance = (npc.Settings.EnemyPosVal.Value.Position - GoalNode.Position).Magnitude
local Speed = 2
local EnemyTweenInfo = TweenInfo.new(Distance/Speed, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local PosTween = TS:Create(npc.Settings.EnemyPosVal, EnemyTweenInfo, {Value = GoalNode.CFrame})
PosTween:Play()
PosTween.Completed:Wait()
end
end)
end
end)
function SpawnNPC(amount)
print("Spawning " .. "NPC" .. " amount of " .. amount)
for i=1, amount do
task.wait(2) -- Spawn delay between each unit
local npc = game:GetService("ServerStorage").ServerSide:Clone()
npc.Parent = game.Workspace.Mobs
npc:PivotTo(CFrame.new(game.Workspace.Nodes[npc.Settings.CurrentNode.Value].Position, game.Workspace.Nodes[npc.Settings.GoalNode.Value].Position))
test:FireAllClients(npc)
print("test")
end
end
SpawnNPC(3)
(Client Side Code)
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
for _, npc in ipairs(game.Workspace.Mobs:GetChildren()) do
local TweenPos = npc.ClientSide.CFrame
local ServerPos = npc.Settings.EnemyPosVal.Value
--Adjust alpha if it's too fast/slow
npc.ClientSide.CFrame = npc.ClientSide.CFrame:Lerp(ServerPos, 1)
end
end)
First of all, so far I figured outthat the value starts from (0,0,0) because I’m not pasting the value of the CFrame of the enemy part into the EnemyPosVal as soon as it starts, it isnt supposed to start at 0,0,0 because I’m pivoting it to the first node and from there I want it to continue to other nodes.
Now in regards to the problem where it reaches the coordinate of the node but doesn’t continue to the next node, I don’t know why.