Imagine if a player was falling at a great speed and while falling/upon impact hit himself on his head. (Painful to just think about), Now I want to detect how long their bodypart for, which body part and how severe it is.
The way I wanted to calculate this is if the player hits this body part for more than 0.5 seconds, the game chooses by random if it should be a cut or a bruise. Otherwise, if it was longer, it’s definitely a scrape.
Now my code is supposed to print out the info but instead, nothing comes out in output. The code looks as such:
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local fatality = {
["Head"] = "Very Fatal",
["Torso"] = "Fatal",
["Left Arm"] = "Moderate",
["Right Arm"] = "Moderate",
["Left Leg"] = "Not that alright",
["Right Leg"] = "Not that alright"
}
humanoid.FreeFalling:Connect(function()
for i, v in pairs(character:GetDescendants()) do
if v:IsA("BasePart") then
v.Touched:Connect(function()
local startCollision = tick()
v.TouchEnded:Connect(function()
local endCollision = tick()
if startCollision and endCollision ~= nil then
if endCollision - startCollision <= 0.5 then
local random = math.random(1, 2)
if random == 1 then -- Cut
for BP, Severity in pairs(fatality) do
if v == BP then
print("Cut, "..v..", "..Severity)
end
end
elseif random == 2 then -- Bruise
for BP, Severity in pairs(fatality) do
if v == BP then
print("Bruise,"..v..", "..Severity)
end
end
end
elseif endCollision - startCollision >= 0.5 then -- scrape
for BP, Severity in pairs(fatality) do
if v == BP then
print("Scrape, "..v..", "..Severity)
end
end
end
end
end)
end)
end
end
end)
How can I fix this issue???