Is there a way to use the function inside 'for' outside?

The function ‘Cosmetics Bullet’ needs outside ‘for’, but I have no idea how to write it. Your feedback on this would be appreciated


for _, part in pairs(game.ReplicatedStorage.bomb:GetDescendants()) do
	if part:IsA("BasePart") and part.Name == 'Random' then
	
		print(part)
		local CosmeticBullet = part:Clone()
		local CosmeticPartProvider = PartCacheModule.new(CosmeticBullet:Clone(), 100, CosmeticBulletsFolder)
	end
end





local CastBehavior = FastCast.newBehavior()
CastBehavior.RaycastParams = CastParams
CastBehavior.MaxDistance = BULLET_MAXDIST
CastBehavior.HighFidelityBehavior = FastCast.HighFidelityBehavior.Default


CastBehavior.CosmeticBulletProvider = CosmeticPartProvider -- there is need a function in 'for' here.

CastBehavior.CosmeticBulletContainer = CosmeticBulletsFolder
CastBehavior.Acceleration = BULLET_GRAVITY
CastBehavior.AutoIgnoreContainer = false 
1 Like

Are you trying to use CosmeticPartProvider outside of the function? If so try removing the “local” to make it a global variable

What is the purpose of the for loop? What are you trying to achieve? I’m just guessing because I don’t know how FastCast works, but I think what you are trying to do is create multiple CastBehaviors for each type of “bomb”? It’s difficult to give any advice or suggestions without knowing what this code is supposed to do.

No way, this is working! Why didn’t I think of this?

This will make it only care about one of the descendants of the bomb model, in which case, why even have a for-loop?

There are many kinds of bombs in the ReplicatedStorage folder
so i Use ‘for loop’ to identify only one part

But why use a for-loop and not just define the part directly?

local Part = nil

for _, bombPart in bomb:GetDescendants() do
    Part = bombPart
end

-- Would be the same as

local Part = bomb.Part

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.