Make each cloned part unique?

Is there a way to make each cloned part unique? I have a projectile system where everytime a player shoots, a projectile is cloned locally, and the same localscript checks to see if this part hit something to destroy it on impact, but if multiple bullets are travelling at the same time, when one hits, every other bullet is also destroyed. How do I go about making each cloned bullet unique so only the one that hits is destroyed?


Can i see the destroy part of your code?

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("Remote_Event_Client")
local remoteEvent2 = ReplicatedStorage:WaitForChild("Remote_Event_Client_Destruction")

function BlowDamage(Arrow) -- Function that destroys the projectile, nothing too fancy. --

local function onProjectileCreate(Head) 
-- Function that makes the projectile for every other client. --
FakeArrow = ReplicatedStorage.Arrow:Clone()
FakeArrow.Parent = Head
FakeArrow.CFrame = Head.CFrame *, 1.5, -1.5)) 
FakeArrow.Velocity = FakeArrow.CFrame.LookVector * 50							

if FakeArrow then

local TouchedConn = remoteEvent2.OnClientEvent:connect(function(v) BlowDamage(FakeArrow) end) 
-- When the original projectile created elsewhere is touched, fire an event to remove the clones. --														
-- Call "onTimerUpdate()" when the server fires the remote event


Actually, I changed it so when the projectile cloned for the other clients touches something, the destroying process happens. And this worked, multiple projectiles were all unique and destroyed properly, but I want to use the remote event to let this script know when the ORIGINAL touches something. When I use this instead, suddenly every clone is destroyed (not the original, just any other client clones currently travelling, regardless if they hit anything.)

You could try naming them with a random name, possibly?

I’m not quite sure if I understood your question, but if you want each cloned part to be unique, you could assign it a random name.

Arrow.Name = "Arrow - " math.random(1, 1000)

This way every arrow has a different name and you’ll be able to identifiy which arrow should be destroyed.

Well, I think you’d rather have the bullet get cloned and destroyed globally not locally so that way the whole server can see it, and then I would put the damage script or kill script inside of the bullet that gets cloned and then for the event that kills or damages the player who got hit add the :Destroy() to the bullet after it hits the player. Also I would recommend using debris to make the bullet get destroyed if it doesn’t hit a player. API Documentation for the Debris Service: Debris | Documentation - Roblox Creator Hub

I found a different solution I am satisfied with by letting the bullet cloned for clients destroy itself when it touches something. The real and fake bullets may be desynced, but since my game will be PvE, the bullets are synced closely enough that when fighting bots which are handled 100% serverside, the projectiles still look smooth by allowing the server to handle damage from the original projectile while the fakes do no damage and destroy themselves on impact.

1 Like