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)
Hi!
As far as I'm concerned there is no errors in your fling script. The issue is that the Part variable does not update itself when you put a new LightExplosion in the workspace. Therefore, you must put the variable inside the function. This is so the variable can update and find the new, replaced LightExplosion part.
-- 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) Part = game.Workspace:WaitForChild("LightExplosion") --Variable goes here! 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)