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
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()
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.
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)
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.