works on singular parts, but not on my character. Why is that
local part = workspace.PartJump
part.Touched:Connect(function(otherPart)
otherPart.Parent.HumanoidRootPart:ApplyImpulse(Vector3.new(0,1000,0))
end)
works on singular parts, but not on my character. Why is that
local part = workspace.PartJump
part.Touched:Connect(function(otherPart)
otherPart.Parent.HumanoidRootPart:ApplyImpulse(Vector3.new(0,1000,0))
end)
the issue is your code assumes otherPart.Parent is the character model, but sometimes otherPart is just a part inside the model. also applyimpulse needs the part to exist and be unanchored, and it works better if you multiply by the part’s mass. you should find the ancestor model, check it has a humanoid and humanoidrootpart, then apply the impulse to the hrp. here’s a working example:
local part = workspace.PartJump
part.Touched:Connect(function(otherPart)
local character = otherPart:FindFirstAncestorOfClass("Model")
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
local hrp = character:FindFirstChild("HumanoidRootPart")
if humanoid and hrp then
hrp:ApplyImpulse(Vector3.new(0,1000,0) * hrp:GetMass())
end
end
end)
Changing velocity properties (via directly setting AssemblyLinearVelocity or other methods) has no effect if it is used from a RunContext that isn’t the network owner of the assembly.
If the part is owned by the server, this function must be called from a server Script (not from a LocalScript or a Script with RunContext set to Enum.RunContext.Client). If the part is owned by a client through automatic ownership, this function can be called from either a client script or a server script; calling it from a client script for a server-owned part will have no effect.
You should also check if the otherPart is part of a character model, like @ttxxjj states.
Your code doesnt work. No matter with what part of a body i touch, when i do “Parent.HumanoidRootPart” i will always get it. I dont need to get character or anything other.
Every part of a character body is unanchored, ig motor6D might mess up with anchored thats my guess. Idk how to make this work
So what script should i use and how should the code look?
The best way to do this would be to tell the client to apply the impulse on parts they own, or handle touch interactions on the client.
Here’s an example, this uses a RemoteEvent to communicate to the client to apply the impulse on the given part.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local re_ApplyImpulse = ReplicatedStorage.ApplyImpulse
re_ApplyImpulse.OnClientEvent:Connect(function(target: BasePart, impulse: Vector3)
target:ApplyImpulse(impulse)
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local re_ApplyImpulse = ReplicatedStorage.ApplyImpulse
local part = workspace.PartJump
local impulse = Vector3.new(0, 1000, 0)
part.Touched:Connect(function(otherPart)
if not otherPart:CanSetNetworkOwnership() then
otherPart:ApplyImpulse(impulse)
return
end
local networkOwner = otherPart:GetNetworkOwner()
if networkOwner then
re_ApplyImpulse:FireClient(networkOwner, otherPart, impulse) -- Tell client to apply impulse on part
else
otherPart:ApplyImpulse(impulse)
end
end)
disabling the root joint (Motor6D) of the character, applying the impulse then re enable the root joint