Need help with KnockBack system

I’m sort of new to scripting so I don’t know how to secure everything properly and yes the humanoid is taking damage

1 Like

I’m not talking about the player argument. It can’t be exploited. I’m talking about all the other parameters. An exploiter can send a “humanoid”, “damage”, and “humrootpart” of their choice if they wanted to as there’s no protection, on both client and server.

1 Like

I know, I was talking about errors, if an exploiter fires the remote event without a character the server will be flooded with errors, I know this can be caused from other lines in that script too, but I was trying to keep my part error-free.

1 Like

Yes I know that. I’m talking about the RemoteEvent parameters, what you’ve done there for the character check is fine. I think we were misunderstanding each others lol.

2 Likes

@offizen Could you try changing the script to this again, I think I might’ve fixed it, also tell me what does it print in output.

1 Like

Try doing:

local KnockBack = Instance.new("BodyVelocity");
KnockBack.MaxForce = Vector3.new(300000,300000,300000); -- (I'd keep this low, there's no need to use math.huge. It would just make the knockback jittery)
KnockBack.Velocity = (humrootpart.Position - player.Character.HumanoidRootPart.Position).Unit * Speed;
KnockBack.Parent = humrootpart;
1 Like

Sorry, I had a class so I couldn’t respond but it still just launches them in the direction the other player is facing

1 Like

Nothing is printing in the output

2 Likes

Could you try using this for debugging?

local KnockBack = Instance.new("BodyVelocity", humrootpart)
KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
local Direction = (humrootpart.Position - player.Character.HumanoidRootPart.Position).Unit
KnockBack.Velocity = Direction * Speed
print("Knockback direction ", Direction)

It should print something in the output

1 Like

Oh yeah true, I know why. Do this:

KnockBack.Velocity = (humrootpart.Position - player.Character.HumanoidRootPart.Position).Unit * -Speed

(Speed is negative now, this should fix it)

1 Like

Did you try turning off colliding of all player parts?

1 Like

It still hasn’t worked unfortunately

1 Like

I used your code and it says

Knockback direction  NAN, NAN, NAN  

though I am using it on a dummy so maybe that’s why

1 Like

Sorry but how would I do that?

1 Like

Oh I understand the problem, you were giving the humrootpart of the attacker, not the victim, in your client code make it so it uses the victim’s HumanoidRootPart instead of the attacker’s at the line punchEvent:FireServer(humanoid, damage, humrootpart)

1 Like

Sorry but how would I be able to fix it on the server script after?

1 Like

The server script is fine, just change these in the local script.

1 Like

Well,

for _,v in pairs (Character:GetChildren()) do
        if v:IsA("Part") then
            v.CanCollide = false
        end
    end

Basically, it will turn any possible part Collide to false. As I remember it shouldn’t change Torso and HumanoidRootPart.

I don’t clearly remember which, but in toolbox there was a blackhole model. Just open a new place, find it there, then put this asset in this place (there must be script which pulls player using BodyMover, basically, it’s same what you are trying to do, but instead of knocking back it pulls)

EDIT: Found it. You can delete all parts except Singularity and leave only Script in it (without attract)

1 Like

everyone in this thread is doing too much just play with the velocity value a little bit and youre issue will be fixed

2 Likes

I’ve re-written the code and made it all server-sided so now everything works like I want it to. Thanks to everyone for helping