#debris help

1 messages · Page 1 of 1 (latest)

zinc axle
#

how would i add debris to this im learning lua and made this script but i dont know how i would add debris to it when connection happens

#
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")

local fireballTemplate = ReplicatedStorage.Extra.FireBall.FireBall

local fireballModule = {}


local FireBallCooldown = {}
local cooldown = 1
local lifetime = 4
local speed = 150 -- studs/sec

function fireballModule.LaunchFireBall(player, targetPosition)

    if FireBallCooldown[player] and time() - FireBallCooldown[player] < cooldown then
        return
    end

    FireBallCooldown[player] = time()

    local char = player.Character or player.CharacterAdded:Wait()

    print(targetPosition)

    local origin = char:FindFirstChild("HumanoidRootPart").Position
    local direction = (targetPosition - origin).Unit

    local forwardOffset = 5
    local spawnPos = origin + (direction * forwardOffset)

    local LaunchedFireball = fireballTemplate:Clone()
    LaunchedFireball.Parent = workspace.FireBall.FireBallClones
    LaunchedFireball.CFrame = CFrame.new(spawnPos, spawnPos + direction)
    LaunchedFireball.Anchored = false
    LaunchedFireball.CanCollide = false
    LaunchedFireball.Name = "ClonedFireball"

    local FireBallSound = Instance.new("Sound")
    FireBallSound.SoundId = "rbxassetid://9063468624"
    FireBallSound.Parent = LaunchedFireball
    FireBallSound.Playing = true

    local attachment = Instance.new("Attachment", LaunchedFireball)

    local lv = Instance.new("LinearVelocity")
    lv.Attachment0 = attachment
    lv.VectorVelocity = direction * speed
    lv.MaxForce = math.huge
    lv.RelativeTo = Enum.ActuatorRelativeTo.World
    lv.Parent = LaunchedFireball
#

last bit ```lua
local connection
connection = LaunchedFireball.Touched:Connect(function(hit)

    if hit.Parent:IsDescendantOf(player.Character) or hit.Parent.Name == "Handle" then
        connection:Disconnect()
    end

    for _, part in pairs(workspace:GetDescendants()) do
        local humanoid = part.Parent:FindFirstChild("Humanoid")
        local hrp = part.Parent:FindFirstChild("HumanoidRootPart")

        if humanoid and hrp then

            local distance = (hrp.Position - LaunchedFireball.Position).Magnitude
            if distance <= 15 and not hit.Parent:IsDescendantOf(player.Character) then
                humanoid:TakeDamage(0.5)
            end

        end

    end

end)

debris:AddItem(LaunchedFireball, lifetime)

end

return fireballModule

north kraken
#

huh?

harsh fossil
#

read the documentation?

zenith hound
#

but there's a better way to destroy an object after x seconds

#
local destroyDelay = 5
local part = workspace.Part

task.delay(destroyDelay, part.Destroy, part)
harsh fossil
zenith hound
#

I think it's less efficient

harsh fossil
#

It's a service to delete things why would this be made less efficient?

zenith hound
# harsh fossil It's a service to delete things why would this be made less efficient?