I am trying to make a knockback system that effects both players and characters. However, it just has no effect on players, and it doesn’t throw any errors.
Here is the code snippet I use to add the momentum:
(Char1 refers to the character applying the knockback, char2 refers to the one receiving it.)
No clue why it simply refuses to function. All characters are r6, and have all extra parts set on massless.
Do this on a LocalScript for characters. Or, set the network owner to the server for a very short time. Worked fine for me when I made BaseAdmin’s fling command.
(Copied troll fling from provided example to see if it was a velocity problem)
Here’s the set ownership to server script.
['SetToServer'] = function(Char,Time)
local check = Players:GetPlayerFromCharacter(Char)
if check and true == false then
Char.HumanoidRootPart:SetNetworkOwner(nil)
task.wait(Time)
Char.HumanoidRootPart:SetNetworkOwner(check)
end
end,
t.fling = {function(Player, plr)
for _, p in pairs(getPlayerRun(Player, plr)) do
if p.Character then
local pp = p.Character.PrimaryPart
if pp then
local h = p.Character:FindFirstChildWhichIsA("Humanoid")
if h then
h.Sit = true
end
pp:SetNetworkOwner()
pp.AssemblyLinearVelocity += Vector3.new(200, 200, 0)
delay(1, function()
pp:SetNetworkOwnershipAuto()
end)
end
end
end
end, "Fling", '<plr>', 2}
Edit: I noticed your problem is that you did not set the network owner back to the player in a separate thread, so it will yield the current thread.
I don’t set the ownership back in separate thread? Would it be possible for slight elaboration? Should I have a separate function to set ownership back?
If you don’t set ownership back in a separate thread, it will set it to the server and set it back and then add velocity. You need to add velocity while it is on the server or else it will not work.