I Have a full code block that refuses to comply. this is the code
function EmitChildren(Attach)
local Time = 0
for _, Particle in pairs(Attach:GetChildren()) do
if Particle:IsA("ParticleEmitter") then
local Count = Particle:GetAttribute("EmitCount") or 0
Particle:Emit(Count)
end
end
end
-- ... random extra code
local Part = Explosion.Explosion
local E1 = Part:WaitForChild("Part1") -- attachments that house particle emitters
local E2 = Part:WaitForChild("Part2")
local EB = Part:WaitForChild("Bottom")
local NewSound = Sounds.Sparkle:Clone()
NewSound.Parent = Part
NewSound.PlayOnRemove = true
NewSound:Destroy()
EmitChildren(E1) -- emits first particle set
task.wait(1)
- the code is to simply just emit all the particles under an attachment along with playing a sound.
- However NONE of these occur.
- Placing this code farther infront of the script allow for them to work (play the sound and emit the particles) but I simply cannot do that.
- The code is for a custom explosion effect. the particles are its own VFX.
- further down the line the function
EmitChildren(Attach)is played on the other two attachments and work perfect.
- removing the
task.wait(1)causes none of the futureEmitChildren(Attach)to work aswell
- I suspect that the issue is that the texture arent loading fast enough but loading them using the content provider jus stops all the code.
you can see the full script below
local ReplicatedStorage = game.ReplicatedStorage
local TNTClient = ReplicatedStorage.Remotes.TNTClient
local Ragdoll = require(game.ServerScriptService.Ragdoll)
local Sounds = ReplicatedStorage.Sounds
local ExplodeSound = Sounds.Explode
local Debris = game:GetService("Debris")
local ContentProvider = game:GetService("ContentProvider")
local TNT = {}
function Bottom(Part, length)
local rayOrigin = Part.Position
local rayDirection = Vector3.new(0, -length, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {Part}
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
return raycastResult.Position
else
return nil
end
end
function EmitChildren(Attach)
local Time = 0
for _, Particle in pairs(Attach:GetChildren()) do
if Particle:IsA("ParticleEmitter") then
local Count = Particle:GetAttribute("EmitCount") or 0
Particle:Emit(Count)
end
end
--Attach:Destroy()
end
function PreLoad(Attach)
for _, Particle in pairs(Attach:GetChildren()) do
if Particle:IsA("ParticleEmitter") then
ContentProvider:PreloadAsync({Particle.Texture}, function()
warn("something")
end)
end
end
print("All loaded")
end
function TNT.Spawn(
Pos: Vector3,
Range: number,
Damages: NumberArray,
Force: number,
Burns: BoolValue
)
if not Pos then return warn("no position passed") end
if Range < 5 then Range = 5 end
if not Burns then Burns = false end
if not Force then Force = 30 end
if not Damages then Damages = {1, Force * 2} end
local Explosion = script.Explosion:Clone()
Explosion.Parent = workspace
Explosion:ScaleTo(Range/5)
Explosion.PrimaryPart.Position = Pos
local Part = Explosion.Explosion
local E1 = Part:WaitForChild("Part1")
local E2 = Part:WaitForChild("Part2")
local EB = Part:WaitForChild("Bottom")
local NewSound = Sounds.Sparkle:Clone()
NewSound.Parent = Part
NewSound.PlayOnRemove = true
NewSound:Destroy()
EmitChildren(E1)
task.wait(1)
Explosion.PrimaryPart.Touched:Connect(function(hit)
if Explosion.PrimaryPart.CanTouch and not hit.Anchored then
local Difference = Explosion.PrimaryPart.Position - hit.Position
local UnitVector = Difference.Unit
local Velocity = UnitVector * Force * 10e2
local Distance = Difference.Magnitude
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local character = player.Character
local humanoid = character:FindFirstChildOfClass("Humanoid")
local Damage = math.ceil(math.max(Damages[1], Damages[2] * .5 * Distance/Range))
ReplicatedStorage.Bindables.ExplosionHit:Fire(character, hit, Damage)
humanoid:TakeDamage(Damage)
character.PrimaryPart:ApplyImpulse(Velocity)
else
hit:ApplyImpulse(Velocity)
end
end
end)
local NewSound = ExplodeSound:Clone()
NewSound.Parent = Part
NewSound:Destroy()
Part.Transparency = 0
delay(.1, function()
Part.Transparency = 1
end)
task.spawn(function()
if Bottom(Part, Range/4) then
EmitChildren(EB)
end
end)
EmitChildren(E2)
task.wait(.5)
Explosion.PrimaryPart.CanTouch = false
--game:GetService("Debris"):AddItem(Explosion, 3)
end
return TNT
Can someone please tell me what am I doing wrong? been trying to crack this for 5 hours now.

