Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i numerate each cloned part that my script clone?

I want to numerate each ball that are cloned and spawned, So when like 5 secs goes out, it despawn.. Here is my script:

local UserInputService = game:GetService("UserInputService")


local throwing = false


local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Fire = game.Workspace.Effect.Fire:Clone()
local Sound = game.Workspace.Effect.Sound:Clone()


--//Animations
Throw = Instance.new("Animation")
Throw.AnimationId = "rbxassetid://3307466402"
ThrowTrack = Humanoid:LoadAnimation(Throw)

--//Coding
UserInputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.E and not throwing then
		throwing = true
		Humanoid.WalkSpeed = 0
		ThrowTrack:Play()
		Fire.Parent = Character.LeftHand
		local radius = Instance.new("Part")
		radius.Shape = "Ball"
		radius.Anchored = true
		radius.CanCollide = false
		radius.Color = Color3.fromRGB(249, 169, 70)
		radius.Material = Enum.Material.Neon
		radius.Parent = Character.LeftHand
		radius.Size = Vector3.new(2,2,2)
		radius.Position = Character.LeftHand.Position
		Fire.Parent = radius
		Sound.Parent = radius
		Sound:Play()
wait(1)
		throwing = false
		Humanoid.WalkSpeed = 18
	end
end)

1 answer

✓ Accepted answer

We can use the Debris service so that after 5 seconds the ball will be destroyed.

local UserInputService = game:GetService("UserInputService")


local throwing = false


local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Fire = game.Workspace.Effect.Fire:Clone()
local Sound = game.Workspace.Effect.Sound:Clone()


--//Animations
Throw = Instance.new("Animation")
Throw.AnimationId = "rbxassetid://3307466402"
ThrowTrack = Humanoid:LoadAnimation(Throw)

--//Coding
UserInputService.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.E and not throwing then
	local FireClone=Fire:Clone()
        throwing = true
        Humanoid.WalkSpeed = 0
        ThrowTrack:Play()
        FireClone.Parent = Character.LeftHand
        local radius = Instance.new("Part")
        radius.Shape = "Ball"
        radius.Anchored = true
        radius.CanCollide = false
        radius.Color = Color3.fromRGB(249, 169, 70)
        radius.Material = Enum.Material.Neon
        radius.Parent = Character.LeftHand
        radius.Size = Vector3.new(2,2,2)
        radius.Position = Character.LeftHand.Position
        FireClone.Parent = radius
        Sound.Parent = radius
        Sound:Play()
	--add radius to debris service.
	game:GetService("Debris"):AddItem(radius,5)
wait(1)
        throwing = false
        Humanoid.WalkSpeed = 18
    end
end)

2 comments

0

Oh god you actually make me learn something so useful! thanks you! By the ways, quick things apart, how could i make that my "Fire" get into each radius instead of just the current one?

0

@Shematics We make a clone of the fire when the event is fired and use that, it will be destroyed along with the radius when it disappears, I edited the answer to include that.

This discussion is preserved as it was. New answers, comments, and votes are closed.