Align Position not moving on client

I am trying to make client sided movement for a tower defense game I’m working on.
I use a server side script for the absolute position and a local script for the visual representation of the enemy (to avoid replication stutter).

Now my issue is that while the attachments do get set:
image
It doesn’t move the enemies on the client, they aren’t anchored and the force and velocity are the same as the ones on the server so that shouldn’t be an issue.


As you see the ducks (enemies) aren’t moving but the parts are (the parts are spawned on the server and parented to a folder in workspace)

The way I try to move the enemies on the client is by setting Attachment1 to the server enemies attachment. I am passing the correct parameters and they do work and don’t print nil, it’s just that it’s not moving the client enemy.
I am not sure of the issue and this should work but it just doesn’t.
Here is the local script I use to spawn it on the client and make it work (StarterPlayerScripts)

– << Services >> –
local RS = game:GetService(“ReplicatedStorage”)

– << Variables >> –
local events = RS:WaitForChild(“Events”)
local clientEnemy = events:WaitForChild(“ClientEnemy”)

local enemiesFolder = RS:WaitForChild(“EnemiesClient”)

local enemiesF = workspace.Enemies

– << Functions >> –
clientEnemy.OnClientEvent:Connect(function(enemy, serverEnemy)
local enemyName = enemy.Name

local newEnemy = enemiesFolder:FindFirstChild(enemyName … “Client”):Clone()
if newEnemy then
local root = newEnemy:FindFirstChild(“HumanoidRootPart”)

  local alignPos = root:FindFirstChildOfClass("AlignPosition")
  local rotPos = root:FindFirstChildOfClass("AlignOrientation")

  newEnemy.HumanoidRootPart.Position = workspace.Map.Waypoints.waypoints1.EnemySpawn.Position
  newEnemy.Parent = workspace.ClientEnemy
  
  alignPos.Attachment1 = serverEnemy.HumanoidRootPart.Node
  rotPos.Attachment1 = serverEnemy.HumanoidRootPart.Node

  print(alignPos.Attachment0)
  print(alignPos.Attachment1)

else
warn(“No enemy found”)
end
end)

1 Like

What if instead of using AlignPosition, you just used a script that sets the position of the model every frame your target? Something like:

local RunS = game:GetService("RunService")

RunS.Heartbeat:Connect(function()
    model:SetPrimaryPartCFrame(targetPart.CFrame)
end)

You could do something similar with parts. Don’t be afraid to change what you’re currently doing if it’s easier.

1 Like

setting it every frame on the client probably won’t give the same effect as the align position, also I am taking align orientation into consideration here too since that doesn’t work either. Your idea isn’t bad but I think it will cause issues or lag for lower end devices (like mine) while playing.

The Roblox physics engine has to calculate the constraints anyway so if you take the model out of the simulation then it should run faster

maybe, but if I can’t find any other solutions I’ll try yours. I am leaning towards align position more than this because of all the settings it has for movement.

I took your idea into account and did something similar with Lerp, thanks.

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