It’s great to see that even as a new developer you’ve made an attempt first byusing existing resources and then are asking for help on that attempted implementation, an effort that unfortunately is not that common. Thank you for that, genuinely.
So the first thing to get out of the way is the way you’re setting up this all. So far so good, other than that you parent the object first. There’s a performance warning about using the parent argument of Instance.new and parenting first also has that same effect. See here:
To this end, you would just have to flip your code around.
local clickDetector = Instance.new("ClickDetector")
clickDetector.MaxActivationDistance = 10
clickDetector.Parent = button -- Is "button" ever defined in your script?
The next part is that clonedArmor. Seeing the way that you’ve put this script together, it looks like you want to give this armour to players whenever they click, however this’ll only work once and shift the cloned instance between players. Just reference it here and when you actually want to attach it to someone, then go ahead and clone it.
local armor = game:GetService("ServerStorage").Chestpiece
Now from your ClickDetector, this is where you could reference ClickDetector documentation and perhaps also some help from PiL. PlayerWhoClicked is the argument plr in your function, not a property of the ClickDetector. You already have the player, so you can just get their character directly.
clickDetector.MouseClick:Connect(function (plr)
local char = plr.Character
-- Other code
end)
And then finally, from your actual code, that’s where you can work with all the variables you’ve gotten so far and applicable advice above. For example, before attaching the armour, make sure to clone it. In this case, parenting and then welding is okay to do as welds need a frame to attach to a player.
clickDetector.MouseClick:Connect(function (plr)
local char = plr.Character
if char:FindFirstChildOfClass("Humanoid") then
local clonedArmor = armor:Clone()
local torso = char.Torso -- Works only for R6
-- Same weld code down here
end
end)
Add that all up, and that should be a go for you.