I am trying to make a blood sysytem and so far It isn’t working. I copied the script from this video and it doesn’t seem to work (properly). This video is 2 years old and I did have to modify the script a bit due to depricated parts of it.
Blood Script Video
My script:
local bloods = script:WaitForChild("Blood")
local bloodp = script:WaitForChild("ParticleEmitter")
local bloodc = workspace:FindFirstChild("BloodCache")
local tweenService = game:GetService("TweenService")
local playersService = game:GetService("Players")
local raydirectionl
if not bloodc then
bloodc = Instance.new("Folder", workspace)
bloodc.name = "BloodCache"
end
local tweenSize = function(part, duration, direction, goal)
local tween = tweenService:Create(part,
TweenInfo.new(duration, Enum.EasingStyle.Sine, direction),
{size = goal}
)
tween:Play()
return tween
end
local createBlood = function(position)
local randomsize = math.random(2,20) / 10
local bloodclone = bloods:Clone()
bloodclone.Position = position + Vector3.new(0,0.5,0)
bloodclone.Size = Vector3.new(randomsize, 0.1, randomsize)
bloodclone.Parent = bloodc
if math.random(2) == 1 then
bloodclone.blood_splat:Play()
end
return bloodclone
end
local expandblood = function(part)
local randomincrement = math.random(5,10) / 10
local tween = tweenSize(part, 5, Enum.EasingDirection.Out,
Vector3.new(part.Size.X + randomincrement, 0.1, part.Size.Z + randomincrement)
)
spawn(function()
tween.Completed:Wait()
tween:Destroy()
part:Destroy()
end)
end
local raycast = function(character, rayOrigin, rayDirection)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {character, bloodc}
params.FilterType = Enum.RaycastFilterType.Exclude
params.IgnoreWater = true
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, params)
if raycastResult then
return raycastResult
end
end
playersService.PlayerAdded:Connect(function(players)
players.CharacterAdded:Connect(function(character)
local rootPart = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local oldHealth = humanoid.Health
local particlesClone = bloodp:Clone()
particlesClone.Parent = rootPart
humanoid.HealthChanged:Connect(function(health)
if health < oldHealth then
oldHealth = health
spawn(function()
for i = 1, blood_parts_per_hit do
local randomPosition = math.random(-20, 20) / 10
local raycastOrigin = rootPart.Position + Vector3.new(randomPosition, 0, randomPosition)
local raycastDirection = Vector3.new (0, -8, 0)
local raycastResult = raycast(character, raycastOrigin, raycastDirection)
if raycastResult then
particlesClone:Emit(2)
delay(0.5, function()
local newBlood = createBlood(raycastResult.Position)
expandblood(newBlood)
delay(blood_destroy_delay, function)
deleteBlood(newBlood)
end)
end
end
wait(math.random(0.5, 2) / 10)
end)
end
end)
end)
end)
Video what the scrpit is doing:
What did I do wrong?