My script is a ragdoll fall damage script and for some reason it works perfect in roblox studio game testing but when i test it in game it doesn’t work most of the time or doesn’t even work at all.
Im trying to figure out how to make it work in game and in studio at the same time
This Is My Script: (it’s a “little” bit messy)
local character = script.Parent.Parent
local humanoid = character.Humanoid
local falldown = script.Parent.Parent
local torso = falldown:WaitForChild("HumanoidRootPart")
local RL = falldown:WaitForChild("Right Leg")
local LL = falldown:WaitForChild("Left Leg")
local RA = falldown:WaitForChild("Right Arm")
local LA = falldown:WaitForChild("Left Arm")
local Head = falldown:WaitForChild("Head")
local Ragdoll = character.Values.Ragdoll
local Value = character.LimbHealths
local VC = character.Values
local RFD = character.RFD
local BodyImpact = RFD.Sounds.NormalFall:GetChildren()
local DamageBodyImpact = RFD.Sounds.DamageFall:GetChildren()
--local torso = character.Torso
--local player = game.Players.LocalPlayer
--local Players = game:GetService("Players")
--local LeftLeg = script.Parent.LimbHealths.LeftLeg
--local RightLeg = script.Parent.LimbHealths.RightLeg
--local Arm2 = script.Parent.LimbHealths.RightArm
--local Arm1 = script.Parent.LimbHealths.LeftArm
--local player = Players:GetPlayerFromCharacter(character)
--falldown = script.Parent
---torso = falldown:WaitForChild("Torso")
--humanoid = falldown:WaitForChild("Humanoid")
debounce = false
task.spawn(function(falling)
local fallTime = 0
local ragTime = 0
local TimesHit = 0
local TimesHitHead = 0
local TimesHitLL = 0
local TimesHitLA = 0
local TimesHitRA = 0
local TimesHitRL = 0
local damage2 = 3
local damage3 = 1
while true do
--if character ~= player.Character then break end
local x = task.wait()
--local T = task.wait()
if falldown:FindFirstChild("HumanoidRootPart") then
if torso.Velocity.Y <= -70 then --and character.HumanoidRootPart.Velocity.Y > -100 then
fallTime = fallTime + x
print("Fall Time Started")
else
--print("FallNo")
wait()
end
--if falldown:FindFirstChild("HumanoidRootPart") then
-- if torso.Velocity.Y <= -1 then
-- ragTime = ragTime + T
-- end
-- end
if not falling then
if not debounce then
debounce = true
if torso.Velocity.Y < -70 and torso.Velocity.Y > -100 and Ragdoll.Value == true then --and character.HumanoidRootPart.Velocity.Y > -100 then
print("Character Above -70")
if fallTime >= 0.01 then
print("Character Above 0.1 fall time")
torso.Touched:Connect(function(hit)
if hit.ClassName == "Part" and Ragdoll.Value == true then --and torso.Velocity.Y <= 0 then
if hit.Name == "Left Arm" or hit.Name == "Right Arm" or hit.Name == "Left Leg" or hit.Name == "Right Leg" or hit.Name == "Head" or hit.Name == "Handle" or hit.Name == "HumanoidRootPart" or hit.Name == "Torso" then
wait()
else
--local Impact1 = BodyImpact[math.random(1, #BodyImpact)]
--Impact1:Play()
if torso.Velocity.Y <= -100 then
VC["Downedable?"].Value = false
else
VC["Downedable?"].Value = true
end
local velocity = fallTime * 50 -- you can play with it until you like
print("Fall Time Was " ..fallTime)
print("Velo2 Was "..torso.Velocity.Y)
--print("Velo was "..velocity)
--local Number = humanoid.Health + torso.Velocity.Y / 1
--print("Floss2 "..torso.Velocity.Y)
if TimesHit == 0 then
local Impact1 = BodyImpact[math.random(1, #BodyImpact)]
local Impact2 = DamageBodyImpact[math.random(1, #DamageBodyImpact)]
if (humanoid.Parent:FindFirstChild("ForceField")) then
wait()
else
if torso.Velocity.Y <= -100 then
print("RealVelo Was "..torso.Velocity.Y)
humanoid.Health = humanoid.Health + torso.Velocity.Y / 1
Impact2:Play()
else
if torso.Velocity.Y <= -70 and torso.Velocity.Y > -100 then
print("RealVelo Was "..torso.Velocity.Y)
humanoid.Health = humanoid.Health + torso.Velocity.Y / 2
Impact1:Play()
end
end
end
print("[Torso] HitPart Was "..hit.Name)
TimesHit += 1
TimesHitHead += 1
TimesHitLL += 1
TimesHitLA += 1
TimesHitRA += 1
TimesHitRL += 1
--print(" TimesHit is Now "..TimesHit)
end
--print("FallDamage???")
--print(Number)
-- print(x)
--fallTime = 0
--TimesHit = 0
end
end
end)
if fallTime >= 0.1 then
RL.Touched:Connect(function(hit)
if hit.ClassName == "Part" and Ragdoll.Value == true then--and torso.Velocity.Y <= 0 then
if hit.Name == "Left Arm" or hit.Name == "Right Arm" or hit.Name == "Left Leg" or hit.Name == "Right Leg" or hit.Name == "Head" or hit.Name == "Handle" or hit.Name == "HumanoidRootPart" or hit.Name == "Torso" then
wait()
else
local velocity = fallTime * 50 -- you can play with it until you like
--print("Fall Time Was " ..fallTime)
--print("Velo was "..velocity)
local Number = humanoid.Health + torso.Velocity.Y / 1
--print("Floss2 "..torso.Velocity.Y)
if TimesHitRL == 0 then
if (humanoid.Parent:FindFirstChild("ForceField")) then
wait()
else
if torso.Velocity.Y <= -100 then
humanoid.Health = humanoid.Health + torso.Velocity.Y / damage2
Value.RightLeg.Value = Value.RightLeg.Value + torso.Velocity.Y / 1
else
if torso.Velocity.Y < -70 and torso.Velocity.Y > -100 then
humanoid.Health = humanoid.Health + torso.Velocity.Y / damage3
Value.RightLeg.Value = Value.RightLeg.Value + torso.Velocity.Y / 2
end
end
end
print("[Right Leg] HitPart Was "..hit.Name)
TimesHitRL += 1
-- print(" TimesHit is Now "..TimesHitRL)
end
-- print("FallDamage???")
-- print(Number)
-- print(x)
-- fallTime = 0
--TimesHit = 0
end
end
end)
if fallTime >= 0.1 then
RA.Touched:Connect(function(hit)
if hit.ClassName == "Part" and Ragdoll.Value == true then---and torso.Velocity.Y <= 0 then
if hit.Name == "Left Arm" or hit.Name == "Right Arm" or hit.Name == "Left Leg" or hit.Name == "Right Leg" or hit.Name == "Head" or hit.Name == "Handle" or hit.Name == "HumanoidRootPart" or hit.Name == "Torso" then
wait()
else
local velocity = fallTime * 50 -- you can play with it until you like
--print("Fall Time Was " ..fallTime)
--print("Velo was "..velocity)
local Number = humanoid.Health + torso.Velocity.Y / 1
--print("Floss2 "..torso.Velocity.Y)
if TimesHitRA == 0 then
if (humanoid.Parent:FindFirstChild("ForceField")) then
wait()
else
if torso.Velocity.Y <= -100 then
humanoid.Health = humanoid.Health + torso.Velocity.Y / damage2
Value.RightArm.Value = Value.RightArm.Value + torso.Velocity.Y / 1
else
if torso.Velocity.Y < -70 and torso.Velocity.Y > -100 then
humanoid.Health = humanoid.Health + torso.Velocity.Y / damage3
Value.RightArm.Value = Value.RightArm.Value + torso.Velocity.Y / 2
end
end
end
print("[Right Arm] HitPart Was "..hit.Name)
TimesHitRA += 1
-- print(" TimesHit is Now "..TimesHitRA)
end
--print("FallDamage???")
--print(Number)
--print(x)
--fallTime = 0
--TimesHit = 0
end
end
end)
if fallTime >= 0.1 then
LL.Touched:Connect(function(hit)
if hit.ClassName == "Part" and Ragdoll.Value == true then---and torso.Velocity.Y <= 0 then
if hit.Name == "Left Arm" or hit.Name == "Right Arm" or hit.Name == "Left Leg" or hit.Name == "Right Leg" or hit.Name == "Head" or hit.Name == "Handle" or hit.Name == "HumanoidRootPart" or hit.Name == "Torso" then
wait()
else
local velocity = fallTime * 50 -- you can play with it until you like
---- print("Fall Time Was " ..fallTime)
-- print("Velo was "..velocity)
local Number = humanoid.Health + torso.Velocity.Y / 1
-- print("Floss2 "..torso.Velocity.Y)
if TimesHitLL == 0 then
if (humanoid.Parent:FindFirstChild("ForceField")) then
wait()
else
if torso.Velocity.Y <= -100 then
humanoid.Health = humanoid.Health + torso.Velocity.Y / damage2
Value.LeftLeg.Value = Value.LeftLeg.Value + torso.Velocity.Y / 1
else
if torso.Velocity.Y < -70 and torso.Velocity.Y > -100 then
humanoid.Health = humanoid.Health + torso.Velocity.Y / damage3
Value.LeftLeg.Value = Value.LeftLeg.Value + torso.Velocity.Y / 2
end
end
end
print("[Left Leg] HitPart Was "..hit.Name)
TimesHitLL += 1
-- print(" TimesHit is Now "..TimesHitLL)
end
-- print("FallDamage???")
-- print(Number)
-- print(x)
--fallTime = 0
--TimesHit = 0
end
end
end)
if fallTime >= 0.1 then
LA.Touched:Connect(function(hit)
if hit.ClassName == "Part" and Ragdoll.Value == true and torso.Velocity.Y <= 0 then
if hit.Name == "Left Arm" or hit.Name == "Right Arm" or hit.Name == "Left Leg" or hit.Name == "Right Leg" or hit.Name == "Head" or hit.Name == "Handle" or hit.Name == "HumanoidRootPart" or hit.Name == "Torso" then
wait()
else
local velocity = fallTime * 50 -- you can play with it until you like
--print("Fall Time Was " ..fallTime)
--print("Velo was "..velocity)
local Number = humanoid.Health + torso.Velocity.Y / 1
--print("Floss2 "..torso.Velocity.Y)
if TimesHitLA == 0 then
if (humanoid.Parent:FindFirstChild("ForceField")) then
wait()
else
if torso.Velocity.Y <= -100 then
humanoid.Health = humanoid.Health + torso.Velocity.Y / damage2
Value.LeftArm.Value = Value.LeftArm.Value + torso.Velocity.Y / 1
else
if torso.Velocity.Y < -70 and torso.Velocity.Y > -100 then
humanoid.Health = humanoid.Health + torso.Velocity.Y / damage3
Value.LeftArm.Value = Value.LeftArm.Value + torso.Velocity.Y / 2
end
end
end
print("[Left Arm] HitPart Was "..hit.Name)
TimesHitLA += 1
-- print("TimesHit is Now "..TimesHitLA)
end
-- print("FallDamage???")
-- print(Number)
-- print(x)
--fallTime = 0
--TimesHit = 0
end
end
end)
if fallTime >= 0.1 then
Head.Touched:Connect(function(hit)
if hit.ClassName == "Part" and Ragdoll.Value == true then---and torso.Velocity.Y <= 0 then
if hit.Name == "Left Arm" or hit.Name == "Right Arm" or hit.Name == "Left Leg" or hit.Name == "Right Leg" or hit.Name == "Head" or hit.Name == "Handle" or hit.Name == "HumanoidRootPart" or hit.Name == "Torso" then
wait()
else
local velocity = fallTime * 50 -- you can play with it until you like
-- print("Fall Time Was " ..fallTime)
-- print("Velo was "..velocity)
local Number = humanoid.Health + torso.Velocity.Y / 1
-- print("Floss2 "..torso.Velocity.Y)
if TimesHitHead == 0 then
if (humanoid.Parent:FindFirstChild("ForceField")) then
wait()
else
if torso.Velocity.Y <= -100 then
humanoid.Health = humanoid.Health + torso.Velocity.Y / damage2
Value.Head.Value = Value.Head.Value + torso.Velocity.Y / 1
else
if torso.Velocity.Y < -70 and torso.Velocity.Y > -100 then
humanoid.Health = humanoid.Health + torso.Velocity.Y / damage3
Value.Head.Value = Value.Head.Value + torso.Velocity.Y / 2
end
end
end
print("[Head] HitPart Was "..hit.Name)
TimesHitHead += 1
-- print(" TimesHit is Now "..TimesHitHead)
end
--print("FallDamage???")
--print(Number)
-- print(x)
--fallTime = 0
--TimesHit = 0
end
end
end)
print("TimesHit is "..TimesHit)
print("TimesHitLA is "..TimesHitLA)
print("TimesHitLL is "..TimesHitLL)
print("TimesHitRA is "..TimesHitRA)
print("TimesHitRL is "..TimesHitRL)
print("TimesHitHead is "..TimesHitHead)
fallTime = 0
TimesHit = 0
TimesHitLA = 0
TimesHitLL = 0
TimesHitRA = 0
TimesHitRL = 0
TimesHitHead = 0
end
end
end
end
end
end
end
end
end
end
debounce = false
end
end)