Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

0

use instance.new

2 answers

✓ Accepted answer

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)

3 comments

0

How would I put the accessory into the code? Or ID?

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"

0

I see now

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.

2 comments

0

You’d have to use the Humanoid:AddAccessory() function

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

This discussion is preserved as it was. New answers, comments, and votes are closed.