So, I have a script for adding in particles in a spot.
Here is the snippet:
-- Function to play a particle at a position for x time
function m.PlayAt(Particle, Pos, Rot, Duration, Finish)
Finish = Finish or true
if R:IsClient() then
AtPos:FireServer(Particle, Pos, Rot, Duration, Finish)
return
end
local P = Instance.new("Part", workspace)
P.Anchored = true
P.CanCollide = false
P.Transparency = 1
P.Position = Pos
P.Size = Vector3.new(1,1,1)
P.Orientation = Rot
-- Actually do it
local PC = RS.Effects[Particle]:Clone()
local pobjs = 0
local mpobjs = 0
for _, v in pairs(PC:GetChildren()) do
mpobjs += 1
coroutine.resume(coroutine.create(function()
v.Parent = P
v.Enabled = true
wait(Duration)
v.Enabled = false
wait(v.Lifetime.Max)
v:Destroy()
pobjs += 1
end))
end
while pobjs ~= mpobjs do
wait()
end
P:Destroy()
end
The problem I have with this is that it DOESN’T DESTROY the part. After the whole thing finishes, P:Destroy() just reverts the size and rotation and transparency so it just stays there. I also tried setting the parent to nil, and that STILL didn’t work. Any ideas?
Instance:Destroy() sets the parent to nil. The part still exists while you have references to it. You can check if the part is destroyed with Instance:IsDescendantOf(workspace).
I would also double check that Destroy is running. The part does become parented to nil when Destroy is ran, though it’s possible some other code is putting it back in workspace.
I wouldn’t do this, because the OP wants to be able to create particles whenever.
function m.PlayInPart(Particle, Part, Duration, Finish, b)
Finish = Finish or true
b = b or false
if R:IsClient() then AtPart:FireServer(Particle, Part, Duration, Finish) end
local PC = RS.Effects[Particle]:Clone()
local pobjs = 0
local mpobjs = 0
for _, v in pairs(PC:GetChildren()) do
mpobjs += 1
coroutine.resume(coroutine.create(function()
v.Parent = Part
if not b then
v.Enabled = true
wait(Duration)
v.Enabled = false
else
v:Emit(v.Rate)
end
if Finish then wait(v.Lifetime.Max) end
v:Destroy()
pobjs += 1
end))
end
end
will also spawn a part for no reason…
EDIT: I forgot to mention because I jsut found out it is deleting the part but is making a new one as well… wtf.
That is just making it so the code runs from the server. I just realised i need to return, so I will do that real quick.
Also, currently, I am always running the function from the server. I tested that already.
At the END of the function is when it creates the part.