Two children are nil despite them literally existing?

okay i think what i’m about to show explains everything

function VFX(viewmodel: Model, weapon: Tool)
    local vfxPart: BasePart = viewmodel.Handle:FindFirstChild("VFXPart")
    
    if not vfxPart then return end
    
    local muzzleFlash: ParticleEmitter = vfxPart:FindFirstChild("MuzzleFlash")
    local lightEmitter: PointLight = vfxPart:FindFirstChild("LightEmitter")
    
    if not muzzleFlash or not lightEmitter then
        warn("Muzzle flash or light emitter does not exist!")
        print(muzzleFlash, lightEmitter)
        return
    end
    
    local ammoType: StringValue = weapon:FindFirstChild("AmmoType")
    
    if not ammoType then return end
    
    if ammoType.Value == "NRG" then
        muzzleFlash.Color = Color3.fromRGB(101, 147, 255) -- Blue
    else
        muzzleFlash.Color = Color3.fromRGB(255, 255, 0) -- Yellow
    end
    
    muzzleFlash:Emit(1)
    
    coroutine.wrap(function()
        lightEmitter.Enabled = true
        task.wait(0.01)
        lightEmitter.Enabled = false
    end)()
end

image


bruh??

image

am i going crazy???

1 Like

If this is client-sided, replace FindFirstChild to WaitForChild.

2 Likes

yooooo

i have some crazy BAD news

now it yields infinitely :frowning:

3 Likes

Are you sure that you are passing the correct ViewModel?

first i clone the viewmodel out of ReplicatedStorage

then i set the parent of it to Workspace and pivot it to the player’s camera

then i pass it into the functions

image
image
image

unless i’m doing something stupid??

Nothing bad here.

The effects MIGHT be destroyed or removed by another script.

everything is entirely client sided and nothing gets deleted :slightly_frowning_face:

is this what happens after you take a 2 week break??

ugh…

Maybe add a wait(5) before the script starts to see if something needs to load?

I am having a similar issue with some parts within a model. Did you manage to find a solution?

i don’t exactly remember how i solved this, but i think the VFX part just wasn’t welded to the gun and it fell to the void and disappeared

Try changing all these FindFirstChild to WaitForChild In the whole script.
Unless the FindFirstChild is being used to test for nil. It’s just as fast or it will wait.
If there is an error, it’s not there when you’re calling this… that’s the problem.