How come this script only flings for the first instance of "LightExplosion" In another script a ball named lightexplosion is created in the workspace and then after a few seconds it disappears, so there will never be more than one "LightExplosion" in the server at a time. It only flings the first time it is touched, but when it disappears and another lightexplosion is made it doesn't work on the second one. Here's the script for the fling:
-- Adds a repulsive force to anything this object touches
local Part = game.Workspace:WaitForChild("LightExplosion")
local Debris = game:GetService('Debris')
local CharacterToIgnore = script:WaitForChild('CharacterToIgnore').Value
local MAGNITUDE = 3E4
local TIME_OF_FORCE = 0.2
Part.Touched:connect(function(other)
if other.Parent == CharacterToIgnore or (other.Parent and other.Parent.Parent == CharacterToIgnore) then return end
if not other.Anchored then
local punchSound = script:FindFirstChild('PunchSound')
if punchSound then punchSound:Play() end
local direction = (other.Position - Part.Position).unit
local bodyForce = Instance.new('BodyForce')
bodyForce.force = MAGNITUDE * direction
bodyForce.Parent = other
Debris:AddItem(bodyForce, TIME_OF_FORCE)
end
end)

2 comments
That doesn't work because the part is undefined whenever you do that.
Wait oops sorry I still need the Part variable at the top to define the function. I edited it, try it now and see if it works.