Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a button that when you click all hats get remove ? [closed]

Asked by
bossaeed2 -50
6 years ago

title says it all, ik this is not a request site but i tried my best and i could not do it

Closed as Non-Descriptive by hiimgoodpack and PyccknnXakep

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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)
0
didnt work bossaeed2 -50 — 6y
0
Never heard that Instance.new thing before - Probably best lag solution information I've heard blowup999 659 — 6y
0
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. hiimgoodpack 2009 — 6y
0
Didn't work SpinnyWinny 0 — 6y
Ad
Log in to vote
0
Answered by
blowup999 659 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
ahh didnt work bossaeed2 -50 — 6y
0
Missed a quotationmark after Accessory on line 7 blowup999 659 — 6y