Hi there, I’m trying to make a push tool, So far it hasn’t gone too bad. I have encountered an error where when I push a player or NPC they fly into the air.
ragdoll script
script.Parent.Touched:Connect(function(hit)
if script.Parent.Parent.Pushing.Value == true and hit.Parent ~= script.Parent.Parent.Parent then
for _, v in pairs(hit.Parent:GetDescendants()) do
if v:IsA("Motor6D") then
local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
a0.CFrame = v.C0
a1.CFrame = v.C1
a0.Parent = v.Part0
a1.Parent = v.Part1
local b = Instance.new("BallSocketConstraint")
b.Attachment0 = a0
b.Attachment1 = a1
b.Parent = v.Part0
v:Destroy()
hit.Parent.HumanoidRootPart.CanCollide = false
end
end
end
end)
Have you considered adding a debounce of Targets? Maybe that could be 1 case why he’s moving up as the Touched event is firing so often
Another way you could do it is by just applying some force to the Target relative to where your Character is currently looking at
local Tool = script.Parent
local Pushing = Tool.Parent.Pushing
local PushedTargets = {}
local function Touched(Hit)
local Target = Hit.Parent
local Character = Tool.Parent.Parent
if Target and Character and not table.find(PushedTargets, Target) and Pushing.Value == true then
table.insert(PushedTargets, Target)
local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(500000, 500000, 500000)
BV.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 75
BV.Parent = Hit.Parent
game.Debris:AddItem(BV, 0.5)
for _, v in pairs(Target:GetDescendants()) do
if v:IsA("Motor6D") then
local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
a0.CFrame = v.C0
a1.CFrame = v.C1
a0.Parent = v.Part0
a1.Parent = v.Part1
local b = Instance.new("BallSocketConstraint")
b.Attachment0 = a0
b.Attachment1 = a1
b.Parent = v.Part0
v:Destroy()
Target.HumanoidRootPart.CanCollide = false
end
end
end
end
instead of using bodyVelocity just use Velocity BodyVelocity Would keep pushing the player forever i suggest using Velocity as it dosent make a lot of mess and is simple
Technically the more common use would be is to just use the AssemblyLinearVelocity property but I forgot that existed until now
And Debris:AddItem() basically would create the Object for about the specified duration of time, then afterwards delete it without having the script interfere with it at all
BasePart.Velocity and BasePart.RotVelocity are now deprecated (hidden from Properties window). There were multiple issues in their operation when dealing with a part and its assembly. For example, setting velocity on a part that isn’t a root part just doesn’t work, but it always reads the velocity of the specific part. The AssemblyLinearVelocity and AssemblyAngularVelocity properties, along with the new impulse functions, should provide all of the options necessary for setting specific velocities.
As for reading linear velocities of specific parts or positions, BasePart:GetVelocityAtPosition(Vector3 position)has been added which will return the specific velocity for any point on your assembly (more flexible than BasePart.Velocity).
Sorry I didn’t get back faster, I started playing fnf and completely forgot about this post, the script worked! Thanks a lot for the body velocity suggestion!