-
What do you want to achieve?
I’m trying to make a blood splatter effect. -
What is the issue?
My code seems to be working weird, once I create the particle for the effect, it is supposed to send a raycast each RunService.Heartbeat, half the times the raycast works, and half it doesnt. Even when it does work sometimes only the raycast of 2 out of 4 particles hits. (I’m creating 4 particles, but all of them are going on the same direction, shouldn’t be the issue tho, since even with all of them going on different directions it wont work)
Server Script
local BloodModule = require(game.ReplicatedStorage.ModuleScript)
while wait(2) do
BloodModule.BloodEffect(script.Parent.HumanoidRootPart, 4)
end
Module script
local TweenService = game:GetService("TweenService")
local module = {}
function module.BloodEffect(Origin, PartAmount)
for Count = 1, PartAmount do
local particle = script.BloodPart:Clone()
particle.Anchored = false
particle.CanCollide = false
particle.Position = Origin.Position
particle.Parent = workspace.Visuals
particle.Velocity = Vector3.new(12, 23, 12)
game.Debris:AddItem(particle, 3)
game:GetService("RunService").Heartbeat:Connect(function()
local rayParams = RaycastParams.new()
rayParams.IgnoreWater = true
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
rayParams.FilterDescendantsInstances = {particle, Origin.Parent}
local raycastResult = workspace:Raycast(particle.Position + particle.Size, Vector3.new(0,-1,0), rayParams)
if raycastResult then
if raycastResult.Instance.Transparency < 1 then
local xy = math.random(3, 4)
local splatter = script.BloodSplatter:Clone()
splatter.Parent = workspace.Visuals
game.Debris:AddItem(splatter, 2.7)
TweenService:Create(splatter, TweenInfo.new(0.2, Enum.EasingStyle.Linear), {Size = Vector3.new(xy, xy, 0.05)}):Play()
splatter.CFrame = CFrame.new(particle.Position, particle.Position + raycastResult.Normal)
task.wait(2)
local Tween = TweenService:Create(splatter.blood, TweenInfo.new(0.7, Enum.EasingStyle.Linear), {Transparency = 1}):Play()
local Tween2 = TweenService:Create(splatter.Decal, TweenInfo.new(0.7, Enum.EasingStyle.Linear), {Transparency = 1}):Play()
end
end
end)
end
end
return module
Hope someone can explain why this is happening, I’m somewhat of a beginner to LUA.