Hi there! Im not entirely too sure if this is a LUA-related question so I'll try be explain the premise detailed as I can.
This game is a defense game. Enemies spawn in on the map, and move to the center. The server handles moving the enemy, damage etc.
I have then tried to render the walking animations and death locally so it looks smooth for the client.
Now, the thing is , this code WORKS when you walk close to them. When they spawn, they look like a standard humanoid not moving. Same thing if you kill the enemy from the distance, the death animation (just the parts fading and floating away) only can be seen if you're in say 50 studs.
Ive tested running thecode on the server and works perfectly, but when moving to the client its 'buggy'.
I have looked at :SetNetworkOwner and it could be something to do with passing the enemy parts for the client to handle maybe? Again, not sure if this a lua related question. Sorry for the long post, thanks.
EDIT: Example GIF: https://gph.is/g/E1WwDLx
All run on a local script, no errors:
game.Workspace.EnemyTempFolder.ChildAdded:Connect(function(v) -- Enemy is spawned in
LocalRender(v)
end)
function move(Time,RightShoulder,LeftShoulder,RightHip,LeftHip) -- Actually move the enemy limbs
if RightShoulder ~= nil and LeftShoulder ~= nil and RightHip~= nil and LeftHip ~= nil then
RightShoulder.MaxVelocity = 0.15
LeftShoulder.MaxVelocity = 0.15
local amplitude = 1
local frequency = 9
local desiredAngle = amplitude * math.sin(Time * frequency)
RightShoulder.DesiredAngle = desiredAngle
LeftShoulder.DesiredAngle = desiredAngle
RightHip.DesiredAngle = -desiredAngle
LeftHip.DesiredAngle = -desiredAngle
end
end
function LocalRender(v)
local Torso = v:WaitForChild("Mobs").Mob1.Torso
local RightShoulder = Torso:WaitForChild("Right Shoulder",1)
local LeftShoulder = Torso:WaitForChild("Left Shoulder",1)
local RightHip = Torso:WaitForChild("Right Hip",1)
local LeftHip = Torso:WaitForChild("Left Hip",1)
if Torso then
connection = Torso.Parent.Human.Died:connect(function() --The enemy has died, play death animation
if Torso.Parent == nil then
connection:Disconnect()
else
-- Death Animation Code Here, works fine. Didnt want to waste lines
end
connection:Disconnect()
end
end)
connection = game:GetService("RunService").Stepped:connect(function() -- Move Enemy
if v then
local curTime = tick()
local deltaTime = curTime - lastTime
lastTime = curTime
move(curTime,RightShoulder,LeftShoulder,RightHip,LeftHip)
else
connection:Disconnect()
end
end)
end
end
