Needing some help with this script

I have a trail gamepass that has been working for months, but I just noticed it is not functioning correctly anymore. Whenever a player resets it is no longer reinserting the “trail” into the players head.

Inside of Server Script Service

local marketplaceservice = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function()
    if marketplaceservice:UserOwnsGamePassAsync(plr.UserId, 10062763) then
        local char = plr.Character or plr.CharacterAdded:wait()
        local attach1 = Instance.new("Attachment",char:WaitForChild("Head"))
        local attach2 = Instance.new("Attachment",char.HumanoidRootPart)
        local trail = game.ServerStorage.Trail:Clone()
        trail.Parent = char.Head
        trail.Attachment0 = attach1
        trail.Attachment1 = attach2
    end
    end)
end)

The trail is located inside of Server Storage

Are there any errors associated with the script?

In the script alone there are no errors. However I do have a button that allows you to toggle the trail on or off. It works fine up until the player resets. After I reset and try to use the toggle the error I get is

“Trail is not a valid member of MeshPart “Workspace.KvngAf.Head” -”

Hm strange because it works in my studio, I reset and it puts the trail in my head like it’s supposed to. It may be an issue with your toggle button or the gamepass itself, try replacing the current ID with an ID from another gamepass that you own from another game or something. Let me know if there are any future issues

Are you using a script that spawns inside the character for the trail?

Because thats the only way that error would happen, cause it doesnt make sense with the other script.

The script is in ServerScriptService, OP said so in their post.

I know that, but read the error.
"Trail is not a valid member of MeshPart “Workspace.KvngAf.Head”
'There is nothing in the above script trying to attach something to the trail itself.

Im having no problems with the code. There might be another script interfering and possibly deleting the Trail.

The error is from a script for the button to toggle the trail, since that script can’t find the trail then it’s an issue outside of that script. Like @kojocrash said it might be another script interfering with it.

I’m doing it in a clear baseplate so there is nothing interfering with it. Even with none of the toggle buttons present.

Okay, then @KvngAf show us the toggle script?

So it doesn’t work with the original script and literally nothing else in the baseplate?

Button inside of the GUI (Local Script)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local trail = ReplicatedStorage:WaitForChild("trail")
local player = game:GetService("Players").LocalPlayer
local plrName = player.Name
local char = game.Workspace:WaitForChild(plrName)
local charHead = char:WaitForChild("Head")


script.Parent.MouseButton1Click:Connect(function()
	trail:FireServer()
	charHead.Trail.Enabled = false
	
end)

ServerScriptService (Server Script)

local ReplicatedStorage = game.ReplicatedStorage
local remoteEvent = ReplicatedStorage:WaitForChild("trail")

remoteEvent.OnServerEvent:Connect(function(player)
	local charHead = workspace:WaitForChild(player.Name).Head
	charHead.Trail.Enabled = false
end)

Yeah even with nothing in the baseplate the original script is not working.

Maybe try:

local ReplicatedStorage = game.ReplicatedStorage
local remoteEvent = ReplicatedStorage:WaitForChild("trail")

remoteEvent.OnServerEvent:Connect(function(player)
	local charHead = workspace:WaitForChild(player.Name).Head
	charHead:WaitForChild("Trail", 200).Enabled = false
end)

Im having no issues with the toggle, I have other game passes that work fine with the toggle. Even when removing the toggle the trail does not reinsert on spawn.

I understand that but I don’t think you realize that scripts run as soon as their instance is created unless it’s disabled. So by adding that wait you’re making sure that the trail does exist before attempting to toggle it. It will just wait until the trail is created.

Try

local charHead = player.Character.Head

Instead of:

local charHead = workspace:WaitForChild(player.Name).Head

Im not using the toggle script. I was only using that to see if an error would come.