I am trying to make a tool that lets you push others with ragdoll.
The problem is that it doesn’t push the player, only ragdolls it.
I have tried to change the order of operations.
Here is the local script that is in the tool:
local tool = script.Parent
local player = game.Players.LocalPlayer
local COOLDOWN = 0.7
local ANIMATION_ID = "rbxassetid://84377870330120"
local canFire = true
local remote = tool:WaitForChild("PushEvent")
tool.Activated:Connect(function()
if not canFire then return end
canFire = false
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if humanoid then
local animator = humanoid:FindFirstChild("Animator")
if animator then
local anim = Instance.new("Animation")
anim.AnimationId = ANIMATION_ID
local track = animator:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action4
track:Play()
end
end
task.delay(0.25, function()
remote:FireServer()
end)
task.wait(COOLDOWN)
canFire = true
end)
Here is the serverscript:
local Debris = game:GetService("Debris")
local tool = script.Parent
local RANGE = 2
local WIDTH, HEIGHT = 6, 4
local DELTA_V = 120
local RAGDOLL_TIME = 2
local remote = tool:WaitForChild("PushEvent")
local function ragdoll(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.PlatformStand = true
end
local motors = {}
for _, joint in pairs(character:GetDescendants()) do
if joint:IsA("Motor6D") then
table.insert(motors, {Motor=joint, Parent=joint.Parent, C0=joint.C0, C1=joint.C1})
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
a1.Parent = joint.Part0
a2.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a1
socket.Attachment1 = a2
a1.CFrame = joint.C0
a2.CFrame = joint.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
joint:Destroy()
end
end
return motors
end
local function standUp(character, motors)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.PlatformStand = false
end
for _, data in ipairs(motors) do
if data.Parent and character.Parent then
local newMotor = Instance.new("Motor6D")
newMotor.Part0 = data.Motor.Part0
newMotor.Part1 = data.Motor.Part1
newMotor.C0 = data.C0
newMotor.C1 = data.C1
newMotor.Parent = data.Parent
end
end
end
local function push(character)
local hrp = character:FindFirstChild("HumanoidRootPart")
if not hrp then return end
local size = Vector3.new(WIDTH, HEIGHT, RANGE)
local cf = hrp.CFrame * CFrame.new(0, 0, -(RANGE/2 + 2))
local partsInBox = workspace:GetPartBoundsInBox(cf, size)
local alreadyHit = {}
local hitboxVisual = Instance.new("Part")
hitboxVisual.Size = size
hitboxVisual.CFrame = cf
hitboxVisual.Anchored = true
hitboxVisual.CanCollide = false
hitboxVisual.CanQuery = false
hitboxVisual.CanTouch = false
hitboxVisual.Transparency = 0.5
hitboxVisual.Color = Color3.fromRGB(255, 0, 0)
hitboxVisual.Parent = workspace
Debris:AddItem(hitboxVisual, 0.15)
for _, part in ipairs(partsInBox) do
local otherChar = part:FindFirstAncestorOfClass("Model")
local hum = otherChar and otherChar:FindFirstChildOfClass("Humanoid")
local otherHRP = otherChar and otherChar:FindFirstChild("HumanoidRootPart")
if not (hum and otherHRP) then continue end
if otherChar == character then continue end
if alreadyHit[otherChar] then continue end
alreadyHit[otherChar] = true
local targetChar = otherChar
local targetHRP = otherHRP
local myHRP = hrp
task.spawn(function()
if not (targetChar and targetHRP and myHRP) then return end
local motors = ragdoll(targetChar)
task.wait(0.05)
local dir = targetHRP.Position - myHRP.Position
dir = Vector3.new(dir.X, 0, dir.Z)
if dir.Magnitude > 0 then
dir = dir.Unit
local impulse = dir * math.max(targetHRP.AssemblyMass * (DELTA_V/2), 30)
local originalOwner = targetHRP:GetNetworkOwner()
targetHRP:SetNetworkOwner(nil)
if targetHRP.ApplyImpulse then
targetHRP:ApplyImpulse(impulse)
else
targetHRP.AssemblyLinearVelocity = impulse
end
targetHRP:SetNetworkOwner(originalOwner)
end
task.wait(RAGDOLL_TIME)
if targetChar.Parent then
standUp(targetChar, motors)
end
end)
end
end
remote.OnServerEvent:Connect(function(player)
local char = player.Character
if char then
push(char)
end
end)