I want to fling the character whenever it touches a part.
What is the issue?
:ApplyImpulse doesn’t seem to work.
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).
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)