#Script to project multiple parts (explosion)

1 messages · Page 1 of 1 (latest)

formal kayak
#

use velocity and some other math bullshit to get the result you are looking for

atomic delta
formal kayak
#

can i see your code for the explosion part?

#

i might have an idea

atomic delta
#
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local function onCharacterAdded(character)
    local rightLeg = character:WaitForChild("Right Leg", 5) or character:WaitForChild("RightLowerLeg", 5)
    if not rightLeg then
        warn("Impossible de trouver la jambe droite.")
        return
    end

    local arbre = workspace:FindFirstChild("MonArbre")
    if not arbre or not arbre:IsA("Model") then
        warn("Le modèle 'MonArbre' n'est pas trouvé ou incorrect.")
        return
    end

    local alreadyExploded = false

    rightLeg.Touched:Connect(function(hit)
        -- Vérifie si la partie touchée appartient à l’arbre
        if hit:IsDescendantOf(arbre) and not alreadyExploded then
            alreadyExploded = true
            print("Explosion de l'arbre détectée !")

            -- Désancre et applique une impulsion sur chaque morceau de l'arbre
            for _, part in pairs(arbre:GetDescendants()) do
                if part:IsA("BasePart") then
                    -- Désancre la partie et permet les collisions
                    part.Anchored = false
                    part.CanCollide = true

                    -- Crée une impulsion aléatoire pour projeter le morceau de l'arbre
                    local explosionForce = Vector3.new(
                        math.random(-1000, 1000),  -- Direction X (gauche/droite)
                        math.random(300, 700),     -- Direction Y (haut/bas)
                        math.random(-1000, 1000)   -- Direction Z (avant/arrière)
                    )

                    

#
-- Applique une impulsion sur la partie
                    local bodyVelocity = Instance.new("BodyVelocity")
                    bodyVelocity.MaxForce = Vector3.new(10000, 10000, 10000)  -- Force maximale pour projeter l'objet
                    bodyVelocity.Velocity = explosionForce
                    bodyVelocity.Parent = part

                    -- Supprime le BodyVelocity après un petit délai pour que l'objet réagisse avec la gravité
                    game:GetService("Debris"):AddItem(bodyVelocity, 0.1)
                end
            end
        end
    end)
end

-- Gérer les respawns du joueur
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
    onCharacterAdded(player.Character)
end
#

That was chatgpt's code about a tree exploding

#

@formal kayak

formal kayak
#

hmmm no idea sadly

rocky spire
atomic delta
formal kayak
rocky spire
atomic delta
#

@formal kayak @rocky spire Ok thanks to you, so I just have to follow the documentation and it should work?