Obtain perks on equipped?

Hi. You know those hats in bee swarm simulator when equipped gives a perk to the player? How can I replicate that? Also, how do I let the player unequip hats and limit them to the amount of hat they can wear? So if they are wearing a hat they will have to unequip it to wear another hat. Thank you for your help!

Well, this can be done in many different ways, the best you can use is probably values & tables.

You can insert NumberValues like ExtraSpeed or ExtraMoney into the hats, and then with a script you can get those hat values and apply them to the player. About the tables, I would use them for the “inventory” system.

Start by creating an empty table, then create a variable that specifies the maximum number of equipped hats. Everytime the player tries to equip a hat, check if the hat count is smaller than the limit by doing something like

local MaxHats = 5 -- maximum number of hats allowed
local EquippedHats = {} -- table to store hats

function AddHat()
   -- the code
end

function EquipHat()
   if #EquippedHats < MaxHats then
       AddHat()
   else
      print("Max number of equipped hats reached")
   end
end

I like this! Could you further define on the number values part? I don’t quite understand it. Then about the hats, how can I make it so that when a player buys a hat it adds it to the inventory?

Use Remote Events & Functions, connect them to a Server-Side script that inserts the bought item into the player inventory’s table.

A number value is an object that can be created with Instance.new() and can store numbers up to 15 digits. Don’t really care so much about the technical details, just keep in mind that you can only store numbers into them 3.14, 5.3535663, 7, etc that are smaller than 2^53 and bigger than -2^53.

image

Hmm. I dont quite get how the number values would corrolate with the perks, because I want it something to be like if the hat is equipped, the player will get a special death scene or have a npc come help him fight. About the Hats, do you have psuedo code for adding the hat to a table and then adding it to the list?