title says it all, ik this is not a request site but i tried my best and i could not do it
COMMUNITY QUESTION
How to make a button that when you click all hats get remove ?
2 answers
This is technically made a fixed version of what blowup999 typed in his answer. Click here to learn about GetAccessories. Click here to see about Instance.new (Using the second argument in Instance.new is bad practice and takes a lot of computer power for it to work), even the wiki says that you shouldn't use the second argument when using the Instance.new. Plus I simplified the UserInputService event to a simple MouseButton1Click event.
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local tb = Instance.new("TextButton")
tb.Parent = plr:WaitForChild("PlayerGui")
tb.MouseButton1Click:Connect(function()
for _,v in pairs(hum:GetAccessories()) do
v:Destroy()
end
end)
Should be in a localscript, tell me if it doesn't work and read about UserInputService for how it tells when click started
local plr = game.Players.LocalPlayer
local tb = Instance.new("TextButton", plr.PlayerGui)
tb.InputBegan:Connect(function(key)
if key.UserInputType == Enum.UserInputType.MouseButton1 then
for i,v in pairs(plr.Character:GetChildren()) do
if v:IsA("Accessory) then
v:Destroy()
end
end
end
end)
2 comments
0
ahh didnt work
0
Missed a quotationmark after Accessory on line 7
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
didnt work
Never heard that Instance.new thing before - Probably best lag solution information I've heard
No, using the second parameter only is important for base parts. Base parts need their gravity, collisions, etc checked, while GUI objects dont have collisions or anything.
Didn't work