I want to be able to run a function completely independent of the script in which it is run.
I created a spaceship which duplicates an explosion particleeffect when it dies, changing its enabled state and then deleting it after it is done. This particle function is called from a ModuleScript.
The script also deletes the model when it is done. However, deleting the model means the script is also deleted, and cannot run the function completely.
the modulescript
function combat.explode(pos)
local explodepart = game:GetService("ReplicatedStorage").GameParts.ParticlePart:Clone()
explodepart.Position = pos
explodepart.Parent = workspace.Effects
spawn(function()
for i, effect in pairs (explodepart.ExplodeAtt:GetChildren()) do
effect.Enabled = true
wait(0.2)
effect.Enabled = false
wait(1)
end
end)
debris:AddItem(explodepart, 1.2)
end
the spaceship's script
myHuman.HealthChanged:Connect(function(newhealth)
if newhealth <= 0 then
print("Died")
myHuman:ChangeState(Enum.HumanoidStateType.Dead)
midpoint:SetAttribute("Units", midpoint:GetAttribute("Units") - myModel:GetAttribute("Tier"))
combat.explode(myBody.Position)
game:GetService("Debris"):AddItem(myModel, 1.2)
else print("Damaged")
print(newhealth)
end
end)
clips of weird stuff happening
There are two different particleemitters, an orange one and a yellow one, which represent the explosion and sparks respectively. However, either only one shows, none show, or they both show multiple times.
How do I go about fixing this