I want to make it so that it splatters onto the wall and sometimes roof if close enough
But everytime I try it just dosent work or the decal faces the wrong way.
if anyone has ideas or know a way to make it work lmk.
local cleanuptime = 20 -- time when its gonna cleanup
function Raycast(origin, direction, ignorelist) -- we move raycasting to a function so the final function doesnt get long
local params = RaycastParams.new()
params.FilterDescendantsInstances = ignorelist
params.FilterType = Enum.RaycastFilterType.Blacklist
local Result = workspace:Raycast(origin, direction, params)
return Result
end
-- final function
function Splatter(c)
local ray = Raycast(c.HumanoidRootPart.Position, Vector3.new(0,-1,0) * 10, {c})
if ray then -- we check if there is a ray
-- there is a ray :D!
if ray.Instance then -- we check if hit something
-- it hit something!
for i = 1,math.random(2,4) do -- 1 splatter is kind of boring why not add more!
local splatter = game.ServerStorage.BloodSplatter:Clone() -- clone the splatter from serverstorage
splatter.Position = ray.Position + Vector3.new(math.random(1,3),0,math.random(1,3)) -- random position
splatter.Orientation = Vector3.new(0,math.random(10,90),0) -- random orientation
splatter.Parent = workspace -- now we parent it to the workspace
spawn(function() -- appear & cleanup
-- tween service!
local tween = game:GetService("TweenService"):Create(splatter.BloodTop, TweenInfo.new(1, Enum.EasingStyle.Sine), {Transparency = 0.2})
tween:Play() -- makes the splatter appear
wait(cleanuptime) -- waits the cleanup time
local clean = game:GetService("TweenService"):Create(splatter.BloodTop, TweenInfo.new(5, Enum.EasingStyle.Sine), {Transparency = 1})
clean:Play()
clean.Completed:Connect(function()
splatter:Destroy() -- destroy the splatter when cleaning is done!
end)
end)
end
end
end
end
function HandleDamage(c, oldHealth, newHealth)
local damageTaken = oldHealth - newHealth
if damageTaken >= 15 then
Splatter(c)
end
end
game.Players.PlayerAdded:Connect(function(P)
P.CharacterAdded:Connect(function(C)
local humanoid = C:WaitForChild("Humanoid")
local lastHealth = humanoid.Health
humanoid.HealthChanged:Connect(function(newHealth)
HandleDamage(C, lastHealth, newHealth)
lastHealth = newHealth
end)
end)
end)
while wait(120) do
for _, part in pairs(workspace:GetChildren()) do
if part:IsA("Part") and part.Name == "BloodSplatter" then
part:Destroy()
end
end
end
-- Small optimization since sometimes it bugged