:ApplyImpulse problem

  1. What do you want to achieve?

I want to fling the character whenever it touches a part.

  1. What is the issue?

:ApplyImpulse doesn’t seem to work.

  1. What solutions have you tried so far?

I tried everything I could find on DevForum.

script.Parent.Touched:Connect(function(hit)
	if not hit.Parent:FindFirstChildOfClass("Humanoid") then return end
	print("through")
	if hit.Parent:IsA("Model") then
		print("more through")
		local humanoidRP = hit.Parent.PrimaryPart
		humanoidRP:ApplyImpulse(humanoidRP.CFrame.LookVector * 3000)
	end
end)

You cannot change the velocity of parts owned by clients on the server, you’ll need to either revoke network ownership temporarily (via BasePart:SetNetworkOwner()), or let the owning client handle it (via RemoteEvents or mover constraints).

i dont understand, what do i need to set the network owner?

You cannot set the velocity of parts you do not have control over, in order to do that, you must either let the owner of that part handle the velocity, or take away ownership to gain control of that part.

Most likely you need to account for the character’s mass when applying the force. You may also need to set the network owner of the character to the server temporarily, and then set it back to the player. If the force is too strong, simply lower it.

If this is a server script:

local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
humanoidRP:SetNetworkOwner()
humanoidRP:ApplyImpulse(humanoidRP.CFrame.LookVector * humanoidRP.AssemblyMass * 3000)
task.wait(0.5)
humanoidRP:SetNetworkOwner(player)

If this is a client script:

humanoidRP:ApplyImpulse(humanoidRP.CFrame.LookVector * humanoidRP.AssemblyMass * 3000)
1 Like

do i need set the network owner for a client script?

The network owner can only be set from a server script. So, you need to use the first snippet of code I wrote.

For a client script, you don’t need to set the network owner.

yea but i have the localscript in the part but the script doesnt work, i tried with a normal script in the part and it works tho so thanks.

humanoidRP:ApplyImpulse(Vector3.yAxis * humanoidRP.AssemblyMass * 3000)
1 Like

I would recommend writing to BasePart.AssemblyLinearVelocity directly, since your intent is to apply velocity (and not impulse).

1 Like

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