I have a script for a weapon where, when swung, spawns a hitbox that does damage to any humanoid in the hitbox. I’ve been trying to find an R6 ragdoll knockback script on youtube (since I’m new to studio and dont know how to make ragdolls myself) but couldnt find anything that worked with the code I have for my weapon.
I found a module ragdoll script on youtube that’s supposedly meant for knockback, but how do I make it so humanoids hit by the weapon’s hitbox actually ragdoll?
my weapon’s code:
local tool = script.Parent
local bat = tool.BatModel
local damage_re = tool:WaitForChild("SwingEvent")
local hitsound = bat.BatHit
local connection = nil --we technically don't need this anymore, but since we set something to it later we have to include it or stop using it
local hitlist = {}
local function inflict_damage(other_object)
if(not hitlist[other_object.Parent]) then --check if the parent has already been seen
local humanoid = other_object.Parent:FindFirstChild("Humanoid")
if humanoid then
hitlist[other_object.Parent] = true --This can be anything other than nil or false. It's the value we get back when we ask what is inside hitlist[other_object.Parent]. It will be nil if it doesn't exist, but will be true in this case if it does exist in the hitlist.
humanoid:TakeDamage(25)
end
for i in hitlist do
hitsound:Play()
end
--We don't disconnect here anymore. If we disconnect, then we will only run this function on the first block we hit, but we want it to run on all of them.
end
end
damage_re.OnServerEvent:Connect(function()
local hitbox = Instance.new("Part",tool)
hitbox.Size = Vector3.new(1,5,1)
hitbox.CanCollide = false
hitbox.Massless = true
hitbox.Transparency = 1 --debug
local weld = Instance.new("Weld",hitbox)
weld.Part0 = bat
weld.Part1 = hitbox
game.Debris:AddItem(hitbox,0.4)
hitlist = {} --resets hitlist by creating a new list
connection = hitbox.Touched:Connect(inflict_damage)
end)
--i got this script on youtube: https://www.youtube.com/watch?v=kb0zcUA7OMg&ab_channel=ManlyCreator
--any changes from the original were made by this dude tlr22 on the devforum so props 2 him
ragdoll module script code:
-- RAGDOLL SCRIPT
local ragdoll = {}
function ragdoll.Start(character)
if character.Ragdoll.Value then return end
character.Ragdoll.Value = true
for i, joint in pairs(character:GetDescendants()) do
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a0 = Instance.new("Attachment")
local a1 = Instance.new("Attachment")
a0.Parent = joint.Part0
a1.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a0
socket.Attachment1 = a1
a0.CFrame = joint.C0
a1.CFrame = joint.C1
socket.LimitsEnabled = true
socket.TwistLimitsEnabled = true
joint.Enabled = false
end
end
character.Humanoid.WalkSpeed = 0
character.Humanoid.JumpPower = 0
character.Humanoid.PlatformStand = true
character.Humanoid.AutoRotate = false
end
function ragdoll.Stop(character)
local hrp = character:FindFirstChild("HumanoidRootPart")
local hum = character:FindFirstChild("Humanoid")
hum.PlatformStand = false
for i, joint in pairs(character:GetDescendants()) do
if joint:IsA("BallSocketConstraint") then
joint:Destroy()
end
if joint:IsA("Motor6D") then
joint.Enabled = true
end
end
character.Ragdoll.Value = false
hum:ChangeState(Enum.HumanoidStateType.GettingUp)
hum.WalkSpeed = 24
hum.JumpPower = 50
hum.AutoRotate = true
end
return ragdoll
--code from youtube: https://www.youtube.com/watch?v=RnXKmpmEJ3s&ab_channel=MajesticDev