How to get only the current part? (idk if this explains)

So, im making a gun system like Isle and this is my 3 topic about it, uh
So, i need to get a part that gets cloned to the workspace, but if i get one i cant get the others cuz it will break the system, so how would i make it so that i can get every one that goes in workspace

idk if i explained this well cuz idk how to explain it

The script

local tool = script.Parent
local remote = tool:WaitForChild("OnShoot")
local shoot_part = tool:WaitForChild("FirePart")
local Attaches = game.ServerStorage:WaitForChild("Shoot")

local Shooting = false

tool.OnShoot.OnServerEvent:Connect(function(player, target)
	local targetpart = target
	if targetpart:IsA("BasePart") and targetpart.Parent:FindFirstChild("ZombieNoid") then
		if not Shooting then
			Shooting = true
			local hu = targetpart.Parent:FindFirstChild("HumanoidRootPart")
			Attaches:Clone().Parent = game.Workspace
			wait(0.2)
			local bullet = game.Workspace.Shoot
			bullet.Attach1.Position = shoot_part.Position
			bullet.Attach2.Position = hu.Position
			wait(3)
			Shooting = false
		end
	end
end)
1 Like

So from my understanding you want to refer to a cloned Instance?
If so then you could just make a new variable like this:

clonedPart = originalPart:Clone()
clonedPart.Parent = workspace
-- etc.

Do correct me if I’m wrong!

but then cloned part will always be that one right? or it will change each time it clones

You want to clone multiple parts? I guess it would be possible if you could somehow have them under something like a table or folder, then you could use a for loop, like this:

local partsTable = {part1,part2,part3}

for index,value in pairs(partsTable) do -- if this doesnt work try partsTable:GetCHildren(), i dont remember which it is :P
    local clonePart = v:Clone()
end

i dont want to clone multiple parts, only one that clones to the workspace multiple times when a player uses the gun, for a gun system
Sorry if that sounded a bit mean i didnt find other way to say

Don’t worry about sounding aggressive, it’s my fault for repeatedly misinterpreting you!
So you want to clone one part multiple times? Could you confirm I got this right?

Edit: If so, you could just try this:

local count = 0
repeat
    -- this is where youd clone the part
count+=1
until count == 5 -- this is how many times you want the script to run
workspace.ChildAdded:Connect(function(newChild)
	if newChild.Name == "" then --some expected name
		--do some code
	end
end)

I believe this might be what you’re looking for. Change the text inside the quotes.

local tool = script.Parent
local remote = tool:WaitForChild("OnShoot")
local shoot_part = tool:WaitForChild("FirePart")
local Attaches = game.ServerStorage:WaitForChild("Shoot")

local Shooting = false

tool.OnShoot.OnServerEvent:Connect(function(player, target)
	local targetpart = target
	if targetpart:IsA("BasePart") and targetpart.Parent:FindFirstChild("ZombieNoid") then
		if not Shooting then
			Shooting = true
			local hu = targetpart.Parent:FindFirstChild("HumanoidRootPart")
			Attaches:Clone().Parent = game.Workspace
			workspace.ChildAdded:Connect(function(newChild)
				if newChild.Name == "" then --some expected name
					--do some code
				end
			end)
			wait(0.2)
			local bullet = game.Workspace.Shoot
			bullet.Attach1.Position = shoot_part.Position
			bullet.Attach2.Position = hu.Position
			wait(3)
			Shooting = false
		end
	end
end)

I’ve added it into the code, I believe this is where you want it although you may want it somewhere else.

ohhh ima try that, thx! also its not your fault misinterpreting, i didnt explain well tho

oh ok ima also try that, thx too!

Both worked lol, thx!

Post must be at least 30 letters

If the problem has been solved then please mark one of the answers as a solution

But uhh 2 people helped, that why i didnt mark it