How do i get the player through a server sided tool.equipped event?

I’m trying to make a torch for my game that dissapears from your inventory after a “heat” value reaches 0, and in order to make this visable, i was making a GUI to show the current heat of the torch, However, the torch functionality script is inside of the torch, so it has to be server-sided. This makes it so I can’t really reference the player. Ive tried to see if there’s a parameter for the tool.equipped event, but there isnt for the player, and so i can’t place the GUI in the player’s playergui.

Does anybody know how i can reference the player holding a tool through a script in the tool? Any and all help is greatly appreciated.

Assuming your tool lies in a dormant container like StarterPack, the Script within it will only begin executing when the tool is copied from StarterPack into the player’s backpack. A player’s backpack is a child of their Player instance, which is what you want. You can derive the player from the server as follows:

local player = tool:FindFirstAncestorOfClass("Player")

Or

local player = tool.Parent.Parent

Additionally, Tool.Equipped fires after the tool is equipped, and when a tool is equipped, it is moved from the player’s backpack into their character. You can use the following method in that context:

local player = Players:GetPlayerFromCharacter(tool.Parent)
1 Like