Trail Doesn't work instantly but should work!

For some reason first need to press the Red Trail button and after that everything works but it should just work from the start

local TrailButtons = script.Parent
local RedButton = TrailButtons.RedTrailPart.Part
local BlueButton = TrailButtons.BlueTrailPart.Part
local PinkButton = TrailButtons.PinkTrailPart.Part
local BlackButton = TrailButtons.BlackTrailPart.Part
local RemoveTrail = TrailButtons.REMOVETRAIL.Part
local TrailTime = 2
local MarketPlaceService = game:GetService("MarketplaceService")
local BlackTrailGamepassID = 28582152
local PinkTrailGamepassID = 28582201
local BlueTrailGamepassID = 28582254
local RedTrailGamepassID = 28582174
local Debounce = false



RedButton.Touched:Connect(function(hit)
	
	if hit.Parent:FindFirstChild("Humanoid") then 
		print("Humanoid found")
		print(hit.Parent.Name)
		local Char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(Char)
		if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
			Debounce = true
			
			local function RedTrail()
				local Name = hit.Parent.Name
				if game.Workspace:FindFirstChild(Name.."Trail") then
					game.Workspace:FindFirstChild(Name.."Trail"):Destroy()
				end
				local Trail = Instance.new("Trail", game.Workspace)
				Trail.Name = hit.Parent.Name.."Trail"
				Trail.Enabled = true
				local Color1 = Color3.new(0.986084, 0, 0.0271763)	
				local Color2 = Color3.new(0.998642, 0.923796, 0.433249)
				Trail.Color = ColorSequence.new(Color1, Color2)
				Trail.Lifetime = TrailTime


				local Attachment0 = Instance.new("Attachment")
				Attachment0.Name = "Attachment0"
				Attachment0.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment0.Position = Vector3.new(0, 1.5, 0)

				local Attachment1 = Instance.new("Attachment")
				Attachment1.Name = "Attachment1"
				Attachment1.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment1.Position = Vector3.new(0, -1.5, 0)

				Trail.Attachment0 = Attachment0
				Trail.Attachment1 = Attachment1
				wait(3)
				Debounce = false
			end
			
			local function PromptPurchase()
				local hasPass = false

				local success, errormessage = pcall(function()
					hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, RedTrailGamepassID)
				end)

				if hasPass == true then
					RedTrail()
				else
					MarketPlaceService:PromptGamePassPurchase(player, RedTrailGamepassID)
				end
				
			end
			PromptPurchase()
			MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, success)
				if success == true and purchasePassID == RedTrailGamepassID then
					RedTrail()
				end
		end
		
	)


BlueButton.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid") then 
		print("Humanoid found")
		print(hit.Parent.Name)
		local Char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(Char)
					if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
						Debounce = true


			local function BlueTrail()
				local Name = hit.Parent.Name
				if game.Workspace:FindFirstChild(Name.."Trail") then
					game.Workspace:FindFirstChild(Name.."Trail"):Destroy()
				end
				local Trail = Instance.new("Trail", game.Workspace)
				Trail.Name = hit.Parent.Name.."Trail"
				Trail.Enabled = true
				local Color1 = Color3.new(0.0937362, 0, 0.998047)	
				local Color2 = Color3.new(0.768658, 0.945312, 0.999542)
				Trail.Color = ColorSequence.new(Color1, Color2)
				Trail.Lifetime = TrailTime


				local Attachment0 = Instance.new("Attachment")
				Attachment0.Name = "Attachment0"
				Attachment0.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment0.Position = Vector3.new(0, 1.5, 0)

				local Attachment1 = Instance.new("Attachment")
				Attachment1.Name = "Attachment1"
				Attachment1.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment1.Position = Vector3.new(0, -1.5, 0)

				Trail.Attachment0 = Attachment0
							Trail.Attachment1 = Attachment1
							wait(3)
							Debounce = false
			end

			local function PromptPurchase()
				local hasPass = false

				local success, errormessage = pcall(function()
					hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, BlueTrailGamepassID)
				end)

				if hasPass == true then
					BlueTrail()
				else
					MarketPlaceService:PromptGamePassPurchase(player, BlueTrailGamepassID)
				end

			end
			PromptPurchase()
			MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, success)
				if success == true and purchasePassID == BlueTrailGamepassID then
					BlueTrail()
				end
		end)

PinkButton.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid") then 
		print("Humanoid found")
		print(hit.Parent.Name)
		local Char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(Char)
		if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
Debounce = true

			local function PinkTrail()
				local Name = hit.Parent.Name
				if game.Workspace:FindFirstChild(Name.."Trail") then
					game.Workspace:FindFirstChild(Name.."Trail"):Destroy()
				end
				local Trail = Instance.new("Trail", game.Workspace)
				Trail.Name = hit.Parent.Name.."Trail"
				Trail.Enabled = true
				local Color1 = Color3.new(0.984909, 0, 0.837095)	
				local Color2 = Color3.new(0.995117, 0.792096, 0.963165)
				Trail.Color = ColorSequence.new(Color1, Color2)
				Trail.Lifetime = TrailTime


				local Attachment0 = Instance.new("Attachment")
				Attachment0.Name = "Attachment0"
				Attachment0.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment0.Position = Vector3.new(0, 1.5, 0)

				local Attachment1 = Instance.new("Attachment")
				Attachment1.Name = "Attachment1"
				Attachment1.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment1.Position = Vector3.new(0, -1.5, 0)

				Trail.Attachment0 = Attachment0
										Trail.Attachment1 = Attachment1
										wait(3)
										Debounce = false
			end

			local function PromptPurchase()
				local hasPass = false

				local success, errormessage = pcall(function()
					hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, PinkTrailGamepassID)
				end)

				if hasPass == true then
					PinkTrail()
				else
					MarketPlaceService:PromptGamePassPurchase(player, PinkTrailGamepassID)
				end

			end
			PromptPurchase()
			MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, success)
				if success == true and purchasePassID == PinkTrailGamepassID then
					PinkButton()
				end
		end)

BlackButton.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid") then 
		print("Humanoid found")
		print(hit.Parent.Name)
		local Char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(Char)
		if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
	Debounce = true

			local function BlackTrail()
				local Name = hit.Parent.Name
				if game.Workspace:FindFirstChild(Name.."Trail") then
					game.Workspace:FindFirstChild(Name.."Trail"):Destroy()
				end
				local Trail = Instance.new("Trail", game.Workspace)
				Trail.Name = hit.Parent.Name.."Trail"
				Trail.Enabled = true
				local Color1 = Color3.new(0, 0, 0)	
				local Color2 = Color3.new(0.790845, 0.803006, 0.798917)
				Trail.Color = ColorSequence.new(Color1, Color2)
				Trail.Lifetime = TrailTime


				local Attachment0 = Instance.new("Attachment")
				Attachment0.Name = "Attachment0"
				Attachment0.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment0.Position = Vector3.new(0, 1.5, 0)

				local Attachment1 = Instance.new("Attachment")
				Attachment1.Name = "Attachment1"
				Attachment1.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment1.Position = Vector3.new(0, -1.5, 0)

				Trail.Attachment0 = Attachment0
													Trail.Attachment1 = Attachment1
													wait(3)
													Debounce = false
			end

			local function PromptPurchase()
				local hasPass = false

				local success, errormessage = pcall(function()
					hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, BlackTrailGamepassID)
				end)

				if hasPass == true then
					BlackTrail()
				else
					MarketPlaceService:PromptGamePassPurchase(player, BlackTrailGamepassID)
				end

			end
			PromptPurchase()
			MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, success)
			if success == true and purchasePassID == BlackTrailGamepassID then
			BlackTrail()
													end end ) 
											end end end ) 
								end end  end ) 
					end end end) 
		end end end)

RemoveTrail.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(Char)
		local Name = player.Name
		if game.Workspace:FindFirstChild(Name.."Trail") then
			game.Workspace:FindFirstChild(Name.."Trail"):Destroy()
			end
	end
	
	
	
end)








Separate all of your touched connections.

1 Like
local TrailButtons = script.Parent
local RedButton = TrailButtons.RedTrailPart.Part
local BlueButton = TrailButtons.BlueTrailPart.Part
local PinkButton = TrailButtons.PinkTrailPart.Part
local BlackButton = TrailButtons.BlackTrailPart.Part
local RemoveTrail = TrailButtons.REMOVETRAIL.Part
local TrailTime = 2
local MarketPlaceService = game:GetService("MarketplaceService")
local BlackTrailGamepassID = 28582152
local PinkTrailGamepassID = 28582201
local BlueTrailGamepassID = 28582254
local RedTrailGamepassID = 28582174
local Debounce = false

RedButton.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then 
		print("Humanoid found")
		print(hit.Parent.Name)
		local Char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(Char)
		if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
			Debounce = true

			local function RedTrail()
				local Name = hit.Parent.Name
				if game.Workspace:FindFirstChild(Name.."Trail") then
					game.Workspace:FindFirstChild(Name.."Trail"):Destroy()
				end
				local Trail = Instance.new("Trail", game.Workspace)
				Trail.Name = hit.Parent.Name.."Trail"
				Trail.Enabled = true
				local Color1 = Color3.new(0.986084, 0, 0.0271763)	
				local Color2 = Color3.new(0.998642, 0.923796, 0.433249)
				Trail.Color = ColorSequence.new(Color1, Color2)
				Trail.Lifetime = TrailTime


				local Attachment0 = Instance.new("Attachment")
				Attachment0.Name = "Attachment0"
				Attachment0.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment0.Position = Vector3.new(0, 1.5, 0)

				local Attachment1 = Instance.new("Attachment")
				Attachment1.Name = "Attachment1"
				Attachment1.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment1.Position = Vector3.new(0, -1.5, 0)

				Trail.Attachment0 = Attachment0
				Trail.Attachment1 = Attachment1
				wait(3)
				Debounce = false
			end

			local function PromptPurchase()
				local hasPass = false

				local success, errormessage = pcall(function()
					hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, RedTrailGamepassID)
				end)

				if hasPass == true then
					RedTrail()
				else
					MarketPlaceService:PromptGamePassPurchase(player, RedTrailGamepassID)
				end

			end
			PromptPurchase()
			MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, success)
				if success == true and purchasePassID == RedTrailGamepassID then
					RedTrail()
				end
			end)
		end
	end
end)

BlueButton.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then 
		print("Humanoid found")
		print(hit.Parent.Name)
		local Char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(Char)
		if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
			Debounce = true


			local function BlueTrail()
				local Name = hit.Parent.Name
				if game.Workspace:FindFirstChild(Name.."Trail") then
					game.Workspace:FindFirstChild(Name.."Trail"):Destroy()
				end
				local Trail = Instance.new("Trail", game.Workspace)
				Trail.Name = hit.Parent.Name.."Trail"
				Trail.Enabled = true
				local Color1 = Color3.new(0.0937362, 0, 0.998047)	
				local Color2 = Color3.new(0.768658, 0.945312, 0.999542)
				Trail.Color = ColorSequence.new(Color1, Color2)
				Trail.Lifetime = TrailTime


				local Attachment0 = Instance.new("Attachment")
				Attachment0.Name = "Attachment0"
				Attachment0.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment0.Position = Vector3.new(0, 1.5, 0)

				local Attachment1 = Instance.new("Attachment")
				Attachment1.Name = "Attachment1"
				Attachment1.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment1.Position = Vector3.new(0, -1.5, 0)

				Trail.Attachment0 = Attachment0
				Trail.Attachment1 = Attachment1
				wait(3)
				Debounce = false
			end

			local function PromptPurchase()
				local hasPass = false

				local success, errormessage = pcall(function()
					hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, BlueTrailGamepassID)
				end)

				if hasPass == true then
					BlueTrail()
				else
					MarketPlaceService:PromptGamePassPurchase(player, BlueTrailGamepassID)
				end

			end
			PromptPurchase()
			MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, success)
				if success == true and purchasePassID == BlueTrailGamepassID then
					BlueTrail()
				end
			end)
		end
	end
end)

PinkButton.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then 
		print("Humanoid found")
		print(hit.Parent.Name)
		local Char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(Char)
		if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
			Debounce = true

			local function PinkTrail()
				local Name = hit.Parent.Name
				if game.Workspace:FindFirstChild(Name.."Trail") then
					game.Workspace:FindFirstChild(Name.."Trail"):Destroy()
				end
				local Trail = Instance.new("Trail", game.Workspace)
				Trail.Name = hit.Parent.Name.."Trail"
				Trail.Enabled = true
				local Color1 = Color3.new(0.984909, 0, 0.837095)	
				local Color2 = Color3.new(0.995117, 0.792096, 0.963165)
				Trail.Color = ColorSequence.new(Color1, Color2)
				Trail.Lifetime = TrailTime


				local Attachment0 = Instance.new("Attachment")
				Attachment0.Name = "Attachment0"
				Attachment0.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment0.Position = Vector3.new(0, 1.5, 0)

				local Attachment1 = Instance.new("Attachment")
				Attachment1.Name = "Attachment1"
				Attachment1.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment1.Position = Vector3.new(0, -1.5, 0)

				Trail.Attachment0 = Attachment0
				Trail.Attachment1 = Attachment1
				wait(3)
				Debounce = false
			end

			local function PromptPurchase()
				local hasPass = false

				local success, errormessage = pcall(function()
					hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, PinkTrailGamepassID)
				end)

				if hasPass == true then
					PinkTrail()
				else
					MarketPlaceService:PromptGamePassPurchase(player, PinkTrailGamepassID)
				end

			end
			PromptPurchase()
			MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, success)
				if success == true and purchasePassID == PinkTrailGamepassID then
					PinkButton()
				end
			end)
		end
	end
end)

BlackButton.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then 
		print("Humanoid found")
		print(hit.Parent.Name)
		local Char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(Char)
		if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
			Debounce = true

			local function BlackTrail()
				local Name = hit.Parent.Name
				if game.Workspace:FindFirstChild(Name.."Trail") then
					game.Workspace:FindFirstChild(Name.."Trail"):Destroy()
				end
				local Trail = Instance.new("Trail", game.Workspace)
				Trail.Name = hit.Parent.Name.."Trail"
				Trail.Enabled = true
				local Color1 = Color3.new(0, 0, 0)	
				local Color2 = Color3.new(0.790845, 0.803006, 0.798917)
				Trail.Color = ColorSequence.new(Color1, Color2)
				Trail.Lifetime = TrailTime


				local Attachment0 = Instance.new("Attachment")
				Attachment0.Name = "Attachment0"
				Attachment0.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment0.Position = Vector3.new(0, 1.5, 0)

				local Attachment1 = Instance.new("Attachment")
				Attachment1.Name = "Attachment1"
				Attachment1.Parent = Char:FindFirstChild("HumanoidRootPart")
				Attachment1.Position = Vector3.new(0, -1.5, 0)

				Trail.Attachment0 = Attachment0
				Trail.Attachment1 = Attachment1
				wait(3)
				Debounce = false
			end

			local function PromptPurchase()
				local hasPass = false

				local success, errormessage = pcall(function()
					hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, BlackTrailGamepassID)
				end)

				if hasPass == true then
					BlackTrail()
				else
					MarketPlaceService:PromptGamePassPurchase(player, BlackTrailGamepassID)
				end

			end
			PromptPurchase()
			MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, success)
				if success == true and purchasePassID == BlackTrailGamepassID then
					BlackTrail()
				end
			end)
		end
	end
end)

RemoveTrail.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local Char = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(Char)
		local Name = player.Name
		if game.Workspace:FindFirstChild(Name.."Trail") then
			game.Workspace:FindFirstChild(Name.."Trail"):Destroy()
		end
	end
end)