Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make the "LightExplosion" part fling after its first instance?

Asked by 7 years ago
Edited 7 years ago

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:

01-- Adds a repulsive force to anything this object touches
02local Part = game.Workspace:WaitForChild("LightExplosion")
03 
04local Debris = game:GetService('Debris')
05 
06local CharacterToIgnore = script:WaitForChild('CharacterToIgnore').Value
07 
08local MAGNITUDE = 3E4
09local TIME_OF_FORCE = 0.2
10 
11Part.Touched:connect(function(other)
12    if other.Parent == CharacterToIgnore or (other.Parent and other.Parent.Parent == CharacterToIgnore) then return end
13    if not other.Anchored then
14        local punchSound = script:FindFirstChild('PunchSound')
15        if punchSound then punchSound:Play() end
View all 22 lines...

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

01-- Adds a repulsive force to anything this object touches
02local Part = game.Workspace:WaitForChild("LightExplosion")
03 
04local Debris = game:GetService('Debris')
05 
06local CharacterToIgnore = script:WaitForChild('CharacterToIgnore').Value
07 
08local MAGNITUDE = 3E4
09local TIME_OF_FORCE = 0.2
10 
11Part.Touched:connect(function(other)
12Part = game.Workspace:WaitForChild("LightExplosion") --Variable goes here!
13    if other.Parent == CharacterToIgnore or (other.Parent and other.Parent.Parent == CharacterToIgnore) then return end
14    if not other.Anchored then
15        local punchSound = script:FindFirstChild('PunchSound')
View all 23 lines...
0
That doesn't work because the part is undefined whenever you do that. True_Warrior 29 — 7y
0
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. SkeletalReality 590 — 7y
Ad

Answer this question