What do you want to achieve? I wanna set the “MuzzleFlash” (ParticleEmitter) Enable to true when the tower fires
What is the issue? It doesn’t set enabled to true when the tower fires
What solutions have you tried so far? None
This is the script (also target is the enemy that tower fires at)
local function fireProjectile(tower, target)
local firePart = tower:FindFirstChild("FirePart")
local muzzleFlash = firePart:FindFirstChild("MuzzleFlash")
if firePart and muzzleFlash then
firePart.MuzzleFlash.Enabled = true
task.wait(1)
firePart.MuzzleFlash.Enabled = false
end
end
Its most likely that either firePart or muzzleFlash doesnt exist, try printing each before the if statement to be sure they exist, this is the most basic testing you can do
local function fireProjectile(tower, target)
local firePart = tower:FindFirstChild("FirePart")
local muzzleFlash = firePart:FindFirstChild("MuzzleFlash")
print(firePart, muzzleFlash)
if firePart and muzzleFlash then
firePart.MuzzleFlash.Enabled = true
task.wait(1)
firePart.MuzzleFlash.Enabled = false
end
end
As @smashman65 said, prints are great for troubleshooting. How are you setting tower? Is it from a model in ReplicatedStorage, or cloned version of that model in the workspace?
local function fireProjectile(tower, target)
print("fireProjectile function called on ", tower.Name, " and ", target.Name)
local firePart = tower:FindFirstChild("FirePart")
local muzzleFlash = firePart:FindFirstChild("MuzzleFlash")
if firePart and muzzleFlash then
firePart.MuzzleFlash.Enabled = true
task.wait(1)
firePart.MuzzleFlash.Enabled = false
end
end
Also, how fast is your ParticleEmitter emitting particles? You could test by increasing or decreasing the properties. If the Particle is emitting at a rate of 0 then you won’t see any particles.
Try testing the game and going into the tower and manually setting it to Enabled to see what the emitter looks like when its enabled.
Well, i called fireProjectile(tower, target) somewhere on my code recently i forgot to do that, now @smashman65 print works but the ParticleEmitter still doesn’t enable, the tower is basically like a tower defense game, it comes from ReplicatedStorage and when placed it goes into a folder in workspace named “Towers” also tower it’s a model, the rate of the ParticleEmitter is 15 and the ParticleEmitter when i set it manually to enabled it’s visible
But my question is where is the script referring to the tower model? Is it referencing the tower that’s the original in ReplicatedStorage and not the one in the workspace? Find out where you called fireProjectile(tower, target) and see what tower it’s actually referencing.
You may be getting the prints if you are successfully referring to the incorrect tower, but if you aren’t enabling the proper ParticleEmitter in the workspace then it won’t work.
Don’t worry i already fixed it, but thanks for trying to help, the problem was that the fire part was going into the sky which made me think it didn’t enable