Gui hat giver without the need for multiple remote events

  1. What do you want to achieve? Keep it simple and clear!

A way to make a GUI that gives hats without the need of a remote event for each hat.

  1. What is the issue? Include screenshots / videos if possible!

I do not wat code, I’m trying to make a hat giver GUI without the need of a remote event for each hat because they cause lagg.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried using a server script for the buttons and click functions.

I know how to debounce, but the problem is that I’m creating a new event every time I add a hat.

1 Like

You don’t need to make multiple remotes for each hat. You can FireServer with a string of text, with the text being the hat ID. Here’s an example of passing a string through a remote event:

LocalScript:

local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage.RemoteEvent

event:FireServer("Hello")

Server Script:

local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage.RemoteEvent

event.OnServerEvent:Connect(function(player, text)
    print(text)  -- Output: "Hello"
end)
1 Like

I see, but what if the hat is a model/accessory that is not from the catalog?

You could just fire it with a string, and if the string equals a value then put the hat on the player.

event.OnServerEvent:Connect(function(player, hat)
    if hat == 'dominus' then
       -- equip hat here
    end
end)

Or you could have a folder with all of the accessories:

local HatsFolder = --
event.OnServerEvent:Connect(function(player, hat)
      local chosenHat = HatsFolder:FindFirstChild(hat)
end)
1 Like

Still doesn’t seem to work here is my code:

—Local—

local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if plr.Character:FindFirstChild("Scarf") then
		
	else
		game.ReplicatedStorage.Hat:FireServer("Scarf")
	end
end)

—Server—

game.ReplicatedStorage.Hat.OnServerEvent:Connect(function(plr, scarf)
	if scarf == "Scarf" then
		local scarfc = game.ReplicatedStorage.EnlistedAccessories.Scarf:Clone(plr.Character)
		scarfc.Parent = plr.Character
	end
end)

Any errors? Do you see anything happening?

Nothing happens when I press the button and there are no errors in the output related to it

When you check the explorer did it clone into the character. You probably have to weld it to the character otherwise you won’t be able to see it.

A very similar problem is discussed here.

No it’s not a model and I’ve welded all the parts together in the accessory and tested it on a dummy.
I’ve done this before, but not with a single remote event so maybe that’s the problem.

Nevermind guys, I fixed it.

It wasn’t related to the code it was in the wrong text button, but thanks for helping!