Help with Trails, Leaderstats, etc

In this script, I attempt to make it so a trail is added to the player when the player clicks a part 50 times.
The code circled in red is the part I’m having issues with.

I know it’s pretty messy but I’m a beginner trying to figure out how it works. No errors in the output box. Help?

(Feel free to rewrite)

Seems like you forgot to clone that trail in ServerStorage. Let me take a few more looks.

Also, that if statement would run once.
You could try to use the .Changed event on that stats.

1 Like
player.CharacterAdded:Connect(function(char)
    local trail = game.ServerStorage.Trail:Clone()
    local charatt1 = Instance.new("Attachment", char:WaitForChild("HumanoidRootPart"))
    local charatt2 = Instance.new("Attachment", char.HumanoidRootPart)

    trail.Attachment0 = charatt1
    trail.Attachment1 = charatt2
    trail.Parent = char.HumanoidRootPart
end)
1 Like

Totally forgot to clone it. I’ll try it and get back to you.

I added clone to it, nothing different. Did I place it somewhere wrong?

Try the script I provided. You never set the trail’s parent to the HumanoidRootPart and you needed to add attachments.

Didn’t I set the trail’s parent to character’s body part when I wrote “charattachment = trail.Parent”?

That’s just redefining the variable charattachment to trail.Parent, which is either nil or ServerStorage (not sure exactly where Cloning puts it)

Nothing changed.

Did I insert everything correctly into my script?

Side question, why are there double parenthesis closing “HumanoidRootPart”?

Yes, everything was inserted correctly. There are two parentheses closing “HumanoidRootPart” because the Instance.new needed a closing parentheses and the WaitForChild for the HumanoidRootPart needed an ending parent.

Now, I’m not sure if this was the problem, but I might need to set the position of the Attachments.

player.CharacterAdded:Connect(function(char)
    local trail = game.ServerStorage.Trail:Clone()
    local charatt1 = Instance.new("Attachment", char:WaitForChild("HumanoidRootPart"))
    local charatt2 = Instance.new("Attachment", char.HumanoidRootPart)
    
    charatt1.Position = Vector3.new(0, -char.HumanoidRootPart.Size.Y/2, 0)
    charatt2.Position = Vector3.new(0, char.HumanoidRootPart.Size.Y/2, 0)
    
    trail.Attachment0 = charatt1
    trail.Attachment1 = charatt2
    trail.Parent = char.HumanoidRootPart
end)
1 Like

Still not fixed. It’s alright, I’ll take it up with a friend of mine. Thanks for the help!

Well, it may be worth a shot to set the trail’s parent before setting the Attachments.

player.CharacterAdded:Connect(function(char)
    local trail = game.ServerStorage.Trail:Clone()
    local charatt1 = Instance.new("Attachment", char:WaitForChild("HumanoidRootPart"))
    local charatt2 = Instance.new("Attachment", char.HumanoidRootPart)
    
    charatt1.Position = Vector3.new(0, -char.HumanoidRootPart.Size.Y/2, 0)
    charatt2.Position = Vector3.new(0, char.HumanoidRootPart.Size.Y/2, 0)
    
    trail.Parent = char.HumanoidRootPart
    trail.Attachment0 = charatt1
    trail.Attachment1 = charatt2
end)
1 Like

You changed charattachments value to trail.parent?? Also try to “if goldstats.value >=” so if their value is greater they can still get the trail

1 Like