How to check which tool is a player holding

Hello, I have a game with a custom hot bar. There is a string value called Selected Item inside the player, and it’s managed by the client. A loop every second will send the value of Selected Item to the server and the server equips it. However, the client can never be trusted so I need a debounce from the server side. But if the player switches items too fast, it can glitch and the server doesn’t show the tool.

Long story short, how do I detect the name of a tool that a player is holding? I need to detect this from the client btw. Thanks for your answer!

Hi first of, don’t have a loop sending signal to the server all the time, it’s not neccessary :smiley:
Instead do the following:

  • Client should fire remote to the server, if it wants to equip anything. Example: Client presses 1 for hotbar 1, in hotbar1 they have a sword. The Client sends signal to the server, that they pressed 1.
  • Server handles what happens next. Server checks what player have equipped in slot 1, and then equip the item for them.

Whenever a player equips a tool just fire a RemoteEvent with the name of the tool also you don’t need that loop.

The loop doesn’t always fire. There is a variable to make sure it only fires when the selected item change. But I’ve fixed the problem now :slight_smile: However, I need to know what tool the player is holding from the server side now. Because I need to remove the item from the player’s hand when they don’t have that item in their inventory folder anymore. How can I check what tool is a player holding from the server side?

It’s the server that determines what tool the client should have. So if you gave the tool from the server, the server would already know. :slight_smile:

Oh ok, I just found a way, which is to loop through the character’s children and picking out the tools. Thanks for the reply though!

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