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:

local player = game.Players.LocalPlayer
local give = script.Parent

give.MouseButton1Click:connect(function()
    local character = player.Character
    local trailClone = Instance.new("Trail", character.Head)
    local HP = character.Head.NeckRigAttachment
                local HRP = character.HumanoidRootPart.RootAttachment
                local trailClone = Instance.new("Trail", character.Head)
                trailClone.Parent = character.HumanoidRootPart
                trailClone.Attachment0 = HP
                trailClone.Attachment1 = HRP
                trailClone.Lifetime = 1
                trailClone.Texture =  "http://www.roblox.com/asset/?id=908770358" 
                trailClone.TextureMode = "Stretch"
                trailClone.TextureLength = 1
                trailClone.LightEmission = 0.2
                trailClone.Transparency = 0.5
                trailClone.MinLength = 0.1
script.Parent.Parent.Destroy1.Visible = true

end)

Disabling Script:

local player = game.Players.LocalPlayer
local give = script.Parent

give.MouseButton1Click:connect(function()
    local char = player.Character
    char.HumanoidRootPart.Trail:Destroy()
    script.Parent.Visible = false
end)

1 answer

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

Try doing

char.HumanoidRootPart:ClearAllChildren()

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

for _, 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