my particles aren’t emitting inside my EmitVFX function. i enabled the VFX before emitting the particles and that works perfectly but the emit method isn’t working for me. thanks for any help! ^^
local VFX = {}
VFX.__index = VFX
local ServerScriptService = game:GetService("ServerScriptService")
local Server = ServerScriptService.Server
local Assets = Server.Assets
local VFXAssets = Assets.VFX
--[[
creates VFX + emit part.
@param name | the name of the VFX part with all the particle emitters, etc inside.
@param CF | cframe
@param parent | make sure its parented to a part.
]]
function VFX.new(name: string, CF: CFrame, parent: Instance?)
local self = setmetatable({}, VFX)
self.effects = {}
local prefab
for _, fx in ipairs(VFXAssets:GetDescendants()) do
if not fx:IsA("BasePart") then continue end
if fx.Name == name then
prefab = fx
break
end
end
if not prefab then
warn("VFX not found: ", name)
return
end
if prefab:IsA("BasePart") then
self.EmitPart = prefab:Clone()
self.EmitPart.Name = prefab.Name.."_Emit"
self.EmitPart.Anchored = true
self.EmitPart.CFrame = CF
self.EmitPart.Transparency = 1
self.EmitPart.CanCollide = false
self.EmitPart.Parent = parent or workspace
for i, instance in ipairs(self.EmitPart:GetChildren()) do
if instance:IsA("ParticleEmitter") then
self.effects[instance.Name.."_"..i] = instance
elseif instance:IsA("Attachment") then
for effectIndex, effect in ipairs(instance:GetChildren()) do
if effect:IsA("ParticleEmitter") then
self.effects[instance.Name.."_"..effectIndex] = effect
end
end
end
end
end
return self
end
function VFX:EmitVFX(EmitCount: number?)
if not self.effects then warn("VFX are missing: ", self.effects) end
task.spawn(function()
if self.effects then
print(self.effects)
for _, effect in pairs(self.effects) do
if effect:IsA("ParticleEmitter") then
local count = EmitCount or effect:GetAttribute("EmitCount") or effect.Rate
effect:Emit(8)
end
end
end
end)
end