UI weld script not welding

I’m making a UI uniform giver that clones items to the character’s body, but the weld script doesn’t work. I copied it from one of my Touched scripts, so I just need help transferring it from touched to activated

local EquipmentName = "Hat"
local Attachment = "Head"
local Offset = CFrame.new(0,0,0)

function Clicked(player)
	if player then
		if player:IsA("Model") then
			local Character = player.CharacterAdded:Wait()
			local Player = game.Players:GetPlayerFromCharacter(Character)
			if Player then
				if Character:FindFirstChild(EquipmentName) == nil then
					local Equipment = script.Parent.Parent:FindFirstChild(EquipmentName)
					if Equipment then
						Equipment = Equipment:Clone()
						local Children = Equipment:GetChildren()
						local Middle = Equipment:FindFirstChild("Middle")
						if Middle then
							for Index, Part in pairs(Children) do
								if Part:IsA("BasePart") then
									local Weld = Instance.new("Weld")
									Weld.Part0 = Middle
									Weld.Part1 = Part
									local C = CFrame.new(Middle.Position)
									local C0 = Middle.CFrame:inverse() * C
									local C1 = Part.CFrame:inverse() * C
									Weld.C0 = C0
									Weld.C1 = C1
									Weld.Parent = Middle
									Part.Anchored = false
									Part.CanCollide = false
								end
							end
							local BodyPart = Character:FindFirstChild(Attachment)
							if BodyPart then
								local MWeld = Instance.new("Weld")
								MWeld.Part0 = BodyPart
								MWeld.Part1 = Middle
								MWeld.C0 = Offset
								MWeld.Parent = MWeld.Part0
								Middle.Transparency = 1
							else
								error("'"..Attachment.."' Is Not A Valid Member Of Character")
							end
							Equipment.Parent = Character
							local Gui = script.Parent.RemoveGUI:Clone()
							Gui.Enabled = true
							Gui.EquipmentName.Value = EquipmentName
							Gui.Parent = Player.PlayerGui
							Gui:WaitForChild("Remove").RemoveScript.Disabled = false
						else
							error("'Middle' Is Not Valid Member Of "..EquipmentName)
						end
					else
						error("'"..EquipmentName.."' Is Not A Valid Member Of "..script.Parent.Parent.Name)
					end
				end
			end
		end
	end
end

script.Parent.Parent.Parent.Activated:Connect(Clicked)

image

The script isn’t running because you didn’t put in any parameters when you called the Clicked function. You can easily get the player from ````game:GetService(“Players”).LocalPlayer```.

Hope this helps!

1 Like

Well yes I did add parameters when I called the function, or else there would have been an error that player doesn’t exist…