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)
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)