Hey guys! I’m making a rain system to my game that uses the trail and particle emitter instances to make the rain drops, but theres a little problem when the drops touchs some part
Video:
Script in StarterCharacterScripts:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local orgDrop = ReplicatedStorage:WaitForChild("water_drop")
local folder = nil
local character = script.Parent
local hrp = character.PrimaryPart or character:WaitForChild("HumanoidRootPart")
local raycastResult = nil
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {character}
rayParams.FilterType = Enum.RaycastFilterType.Exclude
function addDropFunction(drop: BasePart)
drop.Touched:Connect(function(hit)
if hit.CanCollide == true then
drop.Anchored = true
drop.Splash:Emit(4)
task.delay(drop.Splash.Lifetime.Max, function()
if drop then
drop:Destroy()
end
end)
end
end)
task.delay(16, function()
if drop then
drop:Destroy()
end
end)
end
function createDrop()
local newDrop = orgDrop:Clone()
local pos = hrp.Position + Vector3.new(math.random(-32, 32), 0, math.random(-32, 32))
local finalPos = pos + Vector3.new(0, 512, 0)
raycastResult = workspace:Raycast(pos, finalPos, rayParams)
if raycastResult then
return nil
end
newDrop.Position = finalPos
addDropFunction(newDrop)
newDrop.Parent = folder
end
if not workspace:FindFirstChild("water_drops") then
local newFolder = Instance.new("Folder")
newFolder.Name = "water_drops"
newFolder.Parent = workspace
folder = newFolder
else
folder = workspace:FindFirstChild("water_drops")
end
while task.wait() do createDrop() end
As you can see, the touch event takes a while to figure out that it touched the part and creates the splash effect much later than expected. Is there anything I can do?
Thanks to everyone who responded to this post <3