Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Shematics 117
5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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)
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? Shematics 117 — 5y
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. DanzLua 2879 — 5y
Ad

Answer this question