AssemblyLinearVelocity doesn’t work at server start

I’m trying to make a dummy get knocked back when it gets hit by a smash attack, and I am using AssemblyLinearVelocity to do so. It works, but only after the studio server has been active for about 1 minute. Otherwise, the dummy just stands there.

The way it is being implemented is by sending a velocity value to the local script of the player who has initated the attack (using a remote event) which sets the AssemblyLinearVelocity of the dummy’s humanoid root part.

KBRemote.OnClientEvent:Connect(function(Velocity, NPC)
	if NPC == nil then
		humrp.AssemblyLinearVelocity = Velocity
	else
--sets the npc's velocity
		NPC.AssemblyLinearVelocity = Velocity
	end
	
end)

I have already made sure that it gets to the NPC.AssemblyLinearVelocity line, but I’m not sure why its not applying velocity until 1ish minutes after the studio server has began

1 Like

Are you sure the event is even being fired? Add a print statement maybe.

To push the player character, I would recommend using :ApplyImpulse(). You could also use AssemblyLinearVelocity, but you would have to set it to the velocity value every frame for a duration using RunService…

Edit:

local RNS = game:GetService('RunService')
local push_duration = 1 -- as name implies
local conn; conn = RNS.Heartbeat:Connect(function()
   NPC.AssemblyLinearVelocity = Velocity
end)
task.wait(push_duration)
conn:Disconnect()

It would look something like this.

So I used the runtime thing that you put above, and printed out the npc’s assembly velocity and it returned this:

So I feel like it has to do something with the Rig just not responding to the velocity.
And I have checked everypart of the Rig to make sure its unanchored.

Can you show me how your code looks right now?

local RS = game:GetService("ReplicatedStorage")

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humrp = char:WaitForChild("HumanoidRootPart")  

local KBRemote = RS:WaitForChild("Knockback")

KBRemote.OnClientEvent:Connect(function(Velocity, NPC)
	if NPC == nil then
		humrp.AssemblyLinearVelocity = Velocity
	else
		--NPC.AssemblyLinearVelocity = Velocity
		local RNS = game:GetService('RunService')
		local push_duration = 1 -- as name implies
		local conn; conn = RNS.Heartbeat:Connect(function()
			NPC.AssemblyLinearVelocity = Velocity
			print(NPC.AssemblyLinearVelocity)
		end)
		task.wait(push_duration)
		conn:Disconnect()
		print("hit")
	end
	
end)

Try setting the AssemblyLinearVelocity of the humrp instead of the NPC variable.

In my code, when the enemy gets hit by the player’s attack, it checks if its a player or an npc. If it’s an enemy then the server script will fire to the enemy’s knockback script, and the “if NPC == nil then” line will fire. If it’s an NPC, then it fires to the player’s knockback script, and attempts to knockback the npc (the part you are helping me with). When I started a server with two players, they are able to knock each other back, but with the npc rig, it doesn’t seem to work.

I think I found your problem. For the NPC, I suppose you have to set the assemblyLinearVelocity on the server and not the client…

Edit:
Just realized you were using a localScript

When I set the AssLinVel on a server script, it worked, but the knockback was delayed.

Since its server-side, it’ll take some time to replicate to the clients that’s why there is a delay…

To make the delay less apparent, I suppose you could try doing everything server-side…

Edit:
Any help from others would be appreciated

1 Like

I found a work around, just used a linear velocity instead :man_shrugging:. ill give solution to Salam for helping me alot though.

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