Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Trail can't be created again after button destroys it?

This script is suppose to allow players to put on a Trail but the problem I'm having is that if the player clicks the Unequip button to remove the Trail, then they can't click on the Trail button to put another one on.

Trail button script:

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



give.MouseButton1Click:connect(function()
	
	if trail then return end
	trail = true
    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=1311255790" 
				trailClone.TextureMode = "Stretch"
				trailClone.TextureLength = 1
				trailClone.LightEmission = 0.2
				trailClone.Transparency = 0.5
				trailClone.MinLength = 0.1

				
end)

This is the script that removes the Trail when the player clicks the Unequip button:

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

give.MouseButton1Click:connect(function()
    local char = player.Character
    for _, v in pairs(char.HumanoidRootPart:GetChildren()) do if v.Name == "Trail" then v.Parent = nil end end
   
end)

Please help if you can! Thanks in advance.

1 answer

✓ Accepted answer

I don't believe that you ever set your debounce back to false. The script is going back to the beginning because it can't meet the parameters (no explanation because you most likely understand debounce if you are using it). Hope I helped.

-cmgtotalyawesome

EDIT: I would also add something to this script. If the player dies then the trail will be gone but the debounce will still be true. I would connect the died function and set the debounce back to false just in case.

This discussion is preserved as it was. New answers, comments, and votes are closed.