How to make several accessory givers

I’ve got a working accessory giver through remote events but I want to use several accessories, but dont want to make a server scripts and remote event for each accessory, how would I do this?

My serverscript is this:

local hats = game.ReplicatedStorage.Hats

game.ReplicatedStorage.AddHat.OnServerEvent:Connect(function(plr)
	local humanoid = plr.Character.Humanoid
	humanoid:AddAccessory(hats.BloxxerCap:Clone())
end)

Do you still need help with this? If you found a solution already, post it instead of deleting the topic.

(The solution is making it detect if the player wants an accessory on the server)

I do still need help with this. How would I make it detect the accessory?

How does your accessory giver work? Could you send the code for that?

local script in a button to send the remoteevent:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.AddHat:FireServer()
	script.Parent.Visible = false
	script.Parent.Parent.Unequip.Visible = true
end)

serverscript to actually equip the hat:

local hats = game.ReplicatedStorage.Hats

game.ReplicatedStorage.AddHat.OnServerEvent:Connect(function(plr)
	local humanoid = plr.Character.Humanoid
	humanoid:AddAccessory(hats.BloxxerCap:Clone())
end)

It works fine but I want to add more accessories

Both buttons equip the BloxxerCap, how would I seperate them?

Client

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local debounce = false -- Make sure to add a debounce!

script.Parent.MouseButton1Click:Connect(function()
	debounce = true
	
	ReplicatedStorage.AddHat:FireServer(hatType) -- Add a hatType argument
	script.Parent.Visible = false
	script.Parent.Parent.Unequip.Visible = true
	
	task.wait(3)
	debounce = false
end)

Server

local hats = game.ReplicatedStorage.Hats

game.ReplicatedStorage.AddHat.OnServerEvent:Connect(function(plr, hatType) -- You now recieve the hatType on server!
	local humanoid = plr.Character.Humanoid
	humanoid:AddAccessory(hats:FindFirstChild(hatType):Clone())
end)

I also see that you have an unequip button that is seperate from the equip button. You should only use 1 button per accessory and put all of the buttons in a table to hold them. This will help simplify the code a lot especially with a lot of accessories.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.