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)
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.