Im making a dash system in my combat game, and i dont want to use body movers, because doing instance.new everytime player dashes will be heavy on performance (might not be visible in small games, but my game is huge, so i want to make everything extremely optimized. I am using
HumanoidRootPart.Velocity = --whatever
This works perfectly fine when done in a local script, however when it is in server script it has absolutely no effect, why and how can i make it work?
Yeah i had a hunch that it might be because the ownership of the character is on the client, not on the server, but didnt know much about it, so wanted someone to confirm. I will most likely use remoteevents to do it in a local script, as even in your example there is a lag, and that wont be ideal for a dynamic combat system.
Thanks for the explanation, at least now i know what the problem is.
Actually I think I found out the reason why it is lagging, it is because it takes time to replicate that the Humanoid is platform standing from server to client adding a dirty task.wait() seems to do the trick.
This should be smoother and remove the lag caused by :SetNetworkOwnership. Also it has the same effect as applying the knockback locally, so it has a price to pay.
local RE = script.Parent.RemoteEvent
RE.OnServerEvent:Connect(function(player, hitPlayer)
local attackerHRP = player.Character.HumanoidRootPart
local hitPlayerHRP : BasePart = hitPlayer.Character.HumanoidRootPart
local direction = hitPlayerHRP.Position - attackerHRP.Position
print("Server!")
local victimHumanoid = hitPlayer.Character.Humanoid
--hitPlayerHRP:SetNetworkOwner(nil)
victimHumanoid.PlatformStand = true
task.wait(0.1)
local trollFling = Vector3.new(-1,0,0)*50+Vector3.new(0,1,0)*25
hitPlayerHRP.AssemblyLinearVelocity += trollFling
task.wait(0.35)
--hitPlayerHRP:SetNetworkOwner(hitPlayer)
victimHumanoid.PlatformStand = false
print("Can walk now")
end)
This should have the same effect has doing it on a local script because, well since the Player will always control their own character since it maintains NetworkOwnership.
With manually inputting 0.25 seconds lag Network replication lag to simulate IRL Lag, smoother on the victim using the above method but worse for the attacker having to wait twice as long to get a response from the server.