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

Destroy command not working in Trail script?

Asked by 7 years ago

I have a gui that allows players to select a trail from a list. They have to click on a button to enable the trail and then a button will appear that allows them to disable it by destroying the trail. The enabling part works fine but the disabling/destroying part isn't. Please help me fix it.

The GUI is located in StarterGui and it contains Button1 which has the Enabling part, in a local script, and also Destroy1 button which has the Disabling part, also in a local script. When the trail is enabled, it will under the HumanoidRootPart.

Enabling Script:

01local player = game.Players.LocalPlayer
02local give = script.Parent
03 
04give.MouseButton1Click:connect(function()
05    local character = player.Character
06    local trailClone = Instance.new("Trail", character.Head)
07    local HP = character.Head.NeckRigAttachment
08                local HRP = character.HumanoidRootPart.RootAttachment
09                local trailClone = Instance.new("Trail", character.Head)
10                trailClone.Parent = character.HumanoidRootPart
11                trailClone.Attachment0 = HP
12                trailClone.Attachment1 = HRP
13                trailClone.Lifetime = 1
14                trailClone.Texture =  "http://www.roblox.com/asset/?id=908770358"
15                trailClone.TextureMode = "Stretch"
View all 22 lines...

Disabling Script:

1local player = game.Players.LocalPlayer
2local give = script.Parent
3 
4give.MouseButton1Click:connect(function()
5    local char = player.Character
6    char.HumanoidRootPart.Trail:Destroy()
7    script.Parent.Visible = false
8end)

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Try doing

1char.HumanoidRootPart:ClearAllChildren()

or if that conflicts with deleting other stuff inside of the RootPart, do

1for _, v in pairs(char.HumanoidRootPart:GetChildren()) do if v.Name == "Trail" then v.Parent = nil end end

Thats referencing line 6 in the disabling script. I believe your problem is youre deleting one Trail part instead of all of them.

0
Thanks it works now! :D lce_bear 31 — 7y
Ad

Answer this question