Somehow everytime I take damage my blood splatter script not only spawns splatters around the player, but also spawns roughly 10 splatters at 0, 0.
Can someone explain why this is happening and how I can fix this?
Script:
local splatids = {"408754747","408320359","408320438","508050982" }
local char = script.Parent.Parent
local human = char:WaitForChild("Humanoid")
local splatFolder = workspace.DamageDebris.BloodSplatters
human.HealthChanged:Connect(function()
local headcf = char.Head.CFrame
for i = 1, 15 do
local a = Instance.new("Part", nil)
a.Parent = splatFolder
a.Name = "BloodSplat"
a.Size = Vector3.new(math.random(2,5),math.random(2,5),0.05)
a.Transparency = 1
a.CanCollide = false
a.Anchored = true
local decal1 = Instance.new("Decal", a)
decal1.Name = "Blood1"
decal1.Texture = "rbxassetid://"..splatids[math.random(1, 4)]
local decal2 = Instance.new("Decal", a)
decal1.Name = "Blood2"
decal2.Texture = decal1.Texture or decal2.Parent.Blood1.Texture
decal2.Face = "Back"
local dir = Vector3.new(math.random(-50,50),math.random(-50,50),math.random(-50,50)).Unit * 20
local ray = Ray.new(headcf.Position, dir)
local part,pos,normal = workspace:FindPartOnRay(ray, char, false, true)
if part ~= nil then
a.CFrame = CFrame.new(pos,pos + normal)
a.Parent = splatFolder
end
game:GetService("Debris"):AddItem(a, 30)
end
end)