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

How do I make a ClickDetector add a accessory to a player when they click on it?

Asked by 3 years ago
Edited 3 years ago

local debounce = false

script.Parent.ClickDetector.MouseClick:Connect(function()

if debounce == false then

    debounce = true



    -- I Don't Know What To Put Here


    debounce = false

end

end)

0
use instance.new momgggbghghghghg 50 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

ClickDetectors pass in the player that clicks on it as a parameter. You can use it by creating your function with (player) instead of just ()

local debounce = false

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if not debounce then
        debounce = true
        player.Character.Humanoid:AddAccessory(game.ServerStorage.accessory:Clone()) -- clone the accessory or it won't be available to others in the game
        wait(1)
        debounce = false
    end
end)
0
How would I put the accessory into the code? Or ID? MAD_DENISDAILY2 137 — 3y
0
If you're trying to use an accessory from the catalog, there are several plugins you can use to automatically import catalog items. I personally use one called "EasyInsert" OfficerBrah 494 — 3y
0
I see now MAD_DENISDAILY2 137 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I would imagine you have your accessories in server storage so:

local debounce = false
local accessory = game.ServerStorage.tophat -- this is an example, just put your hat or whatever there
script.parent.MouseClick:Connect(function()
    if debounce = false then
        debounce = true
        accessory:Clone(game.Players.localplayer.Character)
        wait(1)
        debounce = false
    end
end)

I'm not a expert on this, but this should work.

0
You’d have to use the Humanoid:AddAccessory() function CrunchChaotic 139 — 3y
0
This won't work. LocalPlayer only exists on LocalScripts, and this should be done in a normal script because you would want everybody on the server to see someone's accessory. Also, Clone doesn't take in any arguments OfficerBrah 494 — 3y

Answer this question