I have an already existing working gun, im trying to add ragdoll knockback when the player or dummy gets shot.
the gun scripts:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local cooldown = false
script.Parent.Activated:Connect(function(hit)
if cooldown == false then
script.Parent.Fire:Play()
script.Parent.MuzzleFlash.MuzzleEffect.Enabled = true
wait(0.1)
script.Parent.MuzzleFlash.MuzzleEffect.Enabled = false
local Target = Mouse.Target
if Target.Parent:FindFirstChild("Humanoid") then
-- Fire Server
game.ReplicatedStorage.Fire:FireServer(Target.Parent)
script.Parent.Name = "RELOADING"
cooldown = true
wait(10)
cooldown = false
script.Parent.Name = "Pistol"
end
end
end)
------------------- Second Gun Script --------------------------
game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(player, Target)
Target.Humanoid.Health -= 100
end)
the ragdoll scripts:
--------------- Main Script ------------------
local ragdollMod = require(script:WaitForChild("Ragdoll"))
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
local ragdoll = Instance.new("BoolValue", character)
ragdoll.Name = "Ragdoll"
end)
end)
---------- 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 = 16
hum.JumpPower = 50
hum.AutoRotate = true
end
return ragdoll
---------------------- Knockback Script -----------------------
local kb = {}
function kb.Start(character, direction)
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp == nil then return end
local att = Instance.new("Attachment", hrp)
local lv = Instance.new("LinearVelocity", att)
lv.MaxForce = 9999999999
lv.VectorVelocity = direction
lv.Attachment0 = att
game.Debris:AddItem(att, 0.1)
end
return kb
----------------------- Disabling (i think) -----------------
local character = script.Parent
local hum = character:WaitForChild("Humanoid")
hum:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
hum:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)