#Script to project multiple parts (explosion)
1 messages · Page 1 of 1 (latest)
Yes, I tried a lot of things but it always gives this result. I was so disappointed that I asked chatgpt and it gives the same result:
This one is from a friend who has exactly the same result as me, if you want I think I still have the one from chatgpt if I look
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
hmmm no idea sadly
There's many reasons why people tell you not to rely on chatgpt. This is one of them.
Yes, but my code had the same bug.
i realize chatgpt does not get some of the documentations correctly. I noticed it in raycast blacklisting items
it doesn't get a lot of documentations correctly, such as using deprecated bodyvelocity and similar
@formal kayak @rocky spire Ok thanks to you, so I just have to follow the documentation and it should work?
Explosions could work yeah