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)
Valkyrop
(aHuman)
September 20, 2022, 9:53pm
2
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
Kaid3n22
(Kaiden)
September 20, 2022, 9:54pm
3
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?
Kaid3n22
(Kaiden)
September 20, 2022, 9:59pm
6
Try the script I provided. You never set the trail’s parent to the HumanoidRootPart and you needed to add attachments.
Kaid3n22:
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)
Didn’t I set the trail’s parent to character’s body part when I wrote “charattachment = trail.Parent”?
Kaid3n22
(Kaiden)
September 20, 2022, 10:02pm
8
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”?
Kaid3n22
(Kaiden)
September 20, 2022, 11:11pm
10
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!
Kaid3n22
(Kaiden)
September 21, 2022, 12:22am
12
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
zR_kty
(zR_kty)
September 21, 2022, 12:58am
13
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