I got a RocketPropulsion in some parts, the parts are flying towards me one after another and attach to my body. I got it working the first time but Im trying to re-use it when I sort of "take off" those parts off my body, I want those same parts to fly to me again. However im not able to re-use it for some reason.. (the code is much longer, I deleted most of the non-important things such as sounds, effects and animations)
function SendSuit_player(player, suitName, ejected, hasSuit)
local character = player.Character
local rocketArray = {}
--This is the first stage, it works perfectly.
if not ejected and not hasSuit then
local CloneSuit = SuitsFolder:FindFirstChild(suitName).Suit:Clone()
CloneSuit.Parent = workspace
CloneSuit.Parent = character
--Adding the force into all parts
for _,v in pairs(CloneSuit:GetChildren()) do
if v:IsA("Model") then
local SuitModels = v
for _,child in pairs(SuitModels:GetChildren()) do
if child.Name == "Main" then
local RP = Instance.new("RocketPropulsion", child)
RP.Name = "FlyTo"
RP.Target = character:FindFirstChild(child.Parent.Name)
RP.MaxSpeed = 120
RP.MaxThrust = 15000
RP.TargetRadius = 1
end
end
end
end
--Putting it in a table
for _,v in pairs(CloneSuit:GetChildren()) do
if v:IsA("Model") then
local SuitModels = v
for _,child in pairs(SuitModels:GetChildren()) do
if child.Name == "Main" then
local MainParts = child
for _,child in pairs(MainParts:GetChildren()) do
if child:IsA("RocketPropulsion") then
local RocketForces = child
table.insert(rocketArray, child)
end
end
end
end
end
end
--Sending each part to player, and using spawn(function() to prevent a delay between each flying part, complicated to explain but this is the way it needs to be.
for _, value in ipairs(rocketArray) do
value.Parent.Anchored = false
value.Parent.RepulsorBlast.repulsorTrail.Enabled = true
value.Parent.Fly:Play()
value:Fire()
wait(.5)
spawn(function()
value.ReachedTarget:Wait()
value:Abort()
local w = Instance.new("Weld", value.Parent)
w.Name = "SuitWeld"
w.Part0 = value.Parent
w.Part1 = character:FindFirstChild(value.Parent.Parent.Name)
end)
end
rocketArray = {} --Cleaning the ray after im finished.
print("cleared array")
else --This is the second stage after I have removed the parts from my body (ejected = true, hasSuit = true). All the values work fine, I checked it.
--All of this the same as before, here im just adding the forces again in my table since I cleared it.
local CloneSuit = character.Suit
for _,v in pairs(CloneSuit:GetChildren()) do
if v:IsA("Model") then
local SuitModels = v
for _,child in pairs(SuitModels:GetChildren()) do
if child.Name == "Main" then
local MainParts = child
MainParts.CanCollide = false
for _,child in pairs(MainParts:GetChildren()) do
if child:IsA("RocketPropulsion") then
local RocketForces = child
table.insert(rocketArray, child)
end
end
end
end
end
end
--Heres the issue, in the line 88, it simply gets stuck, it never gets pass that line, (it did in the first stage tho) and I have no idea why. I tried printing something after it but no luck.
for _, value in ipairs(rocketArray) do
value:Fire()
wait(.5)
spawn(function()
value.ReachedTarget:Wait() --ISSUE
value:Abort()
local w = Instance.new("Weld", value.Parent)
w.Name = "SuitWeld"
w.Part0 = value.Parent
w.Part1 = character:FindFirstChild(value.Parent.Parent.Name)
end)
end
end
end
What could be causing it to not detect when it reaches the target.. I checked the forces in game and they have the correct target set..
Any help is appreciated, ive been stuck like this for a day straight and im frustrated.
Thank you.
