#help with particle emitter

1 messages · Page 1 of 1 (latest)

primal arch
#

i have this script to work with projectiles and it also handles vfx stuff

the annoying thing is just it's not working i evne tested the emitVFX function in the command bar and it worked with the same exact part that the particle emitters are descendant of

local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local debrisFolder = Workspace.Debris

local Projectiles = {}

local function emitParticleEmitter(emitter: ParticleEmitter, emitCount: number)
    print(emitter.Name, emitCount)
    emitter:Emit(emitCount)
end

local function emitVFX(container: Instance)
    for _, emitter in container:GetDescendants() do
        if not emitter:IsA("ParticleEmitter") then
            continue
        end
                
        local emitDelay = emitter:GetAttribute("EmitDelay")
        local emitCount = emitter:GetAttribute("EmitCount") or 20
        
        if emitDelay and emitDelay > 0 then
            task.delay(emitDelay, emitParticleEmitter, emitter, emitCount)
        else
            emitParticleEmitter(emitter, emitCount)
        end
    end
    
    task.delay(10, container.Destroy, container)
end

local function createVFXAtPosition(pos: Vector3, VFXPart: BasePart)
    print(pos)
    local clone = VFXPart:Clone()
    clone.Position = pos
    clone.Parent = debrisFolder
    emitVFX(clone)
end

function Projectiles.fire(startPos: Vector3, endPos: Vector3, projectile: BasePart, additionalException: Instance?)
    local direction = endPos - startPos
    local duration = math.log(1.001 + direction.Magnitude * 0.01) + 0.4
    local force = direction / duration + Vector3.new(0, Workspace.Gravity / 2 * duration, 0)
    
    local clone = projectile:Clone()
    clone.Position = startPos
    clone.Parent = debrisFolder
    clone:ApplyImpulse(force * clone.AssemblyMass)
    
    local rayParams = RaycastParams.new()
    rayParams.FilterType = Enum.RaycastFilterType.Exclude
    rayParams.FilterDescendantsInstances = {debrisFolder, additionalException}
    
    local lastPos = clone.Position
    local destroyThread: thread?
    local steppedConnection: RBXScriptConnection?
    
    destroyThread = task.delay(12, function()
        destroyThread = nil
        
        if steppedConnection then
            steppedConnection:Disconnect()
            steppedConnection = nil
        end
        
        if clone then
            clone:Destroy()
        end
    end)
    
    steppedConnection = RunService.Stepped:Connect(function()
        local rayDirection = lastPos - clone.Position
        if rayDirection.Magnitude == 0 then
            print(0)
            return 
        end
        
        local rayResult = Workspace:Raycast(lastPos, rayDirection, rayParams)
        if rayResult and rayResult.Instance then            
            if destroyThread then
                task.cancel(destroyThread)
                destroyThread = nil
            end
            
            if steppedConnection then
                steppedConnection:Disconnect()
                steppedConnection = nil
            end
            
            local humanoid = rayResult.Instance.Parent:FindFirstChild("Humanoid") or rayResult.Instance.Parent.Parent:FindFirstChild("Humanoid")
            if humanoid then
                createVFXAtPosition(lastPos, ReplicatedStorage.Hit1)
            end
            
            return
        end
        
        lastPos = clone.Position
    end)
end

return Projectiles

the above is the code which is within a module script

#

idk if im missing any word or made typo in the script

#

so it'll be helpful to notify my if something is wrong

craggy comet
#

Try just putting a wait infront of it, or even a renderstepped wait

#

That might fix it

whole pine
#

^ put a task.wait infront of the function youre emitting with

#

serversided vfx has a weird thing where :Emit tries to replicate before the emitter is replicated, so it never actually renders

#

Side note, don't do vfx on the server