Is this good practice?

I was having trouble with the ApplyImpulse method but after looking at some posts regarding my issue I realized it was recommended that you fire to the client to set the impulse because of network ownership.

Client:

local function Impulse(vector)
	player.Character.HumanoidRootPart:ApplyImpulse(vector)
end

ReplicatedStorage.FireImpulse.OnClientEvent:Connect(Impulse)

Server Module:

function Punch:Knockback(root,puncher)
	if Players:GetPlayerFromCharacter(root.Parent) then
		ReplicatedStorage.FireImpulse:FireClient(Players:GetPlayerFromCharacter(root.Parent),puncher.CFrame.LookVector.Unit * 1100)
	else
		root.AssemblyLinearVelocity = puncher.CFrame.LookVector * 100
	end
end

Is this actually a good practice? Are there potential issues with this method?

2 Likes

If you tell the client to apply knockback on itself, there could be a couple of issues:

  • If a laggy player gets hit, the latency will negatively affect everyone else.
  • An exploiter could disable knockback for themselves.
1 Like

How would the exploiter disable knockback if the server is firing to the client?

Never trust the client. Just because the server is telling the client to do something, doesn’t mean they will. Why don’t you just apply impulse on the server???

1 Like

I’m applying an impulse on the player’s humanoidrootpart, they have network ownership so the server can’t do it.

This is an issue I’ve had for a long time because the API says the server can apply an impulse on anything the client owns but that still doesn’t seem to be the case. When I use roblox’s AI assistant they say I wouldn’t be able to apply an impulse on the server because the client has ownership of their humanoidrootpart. I can apply an impulse to dummies and parts though.

I could use assembly linear velocity but Its a little less responsive and I want to find out more about ApplyImpulse.

It usually doesn’t matter if the player has network ownership. Server is still big daddy in the house. Your force may be a little too weak. Gotta amp that boy up. Try going x1000.

Side note: applying knockback on the client is my preferred way. It’s better UX-wise, and has no delays. Yeah, yeah, exploiters can disable this and that, but don’t think they can’t disable server-based knockback. They still own their client.

1 Like

I had the impulse correspond to a lookvector * math.huge but nothing happened.

Check if your character has any anchored parts. :ApplyImpulse() with a lookvector*400-500 will work from the client. You should also check if the if statement you are using to apply this, or rather the code block, is fine. I.e if you use a bool, check if that bool is correct. if can_perform then knockback() end

None of them are anchored and nothing works so far.

I’d like to note that it does work it’s just not working with the ApplyImpulse