Hi,
I need to detect if a player who clicked on the mesh have a tool named “Hamburger” after a click event.
Please help me!
You can check these documentation pages:
I already know this but how to detect if the player who clicked have a hamburger in his inventory?
This is actually really simple. By default, tools are stored in Player.Backpack
; meaning you can just do something like:
if Player.Backpack[ToolName] then
--do stuff
end
Depending on your use case, :FindFirstChild
or :WaitForChild
may be more suitable than directly indexing the tool. A good article on this can be found here.
On another note, I do not recommend ClickDetectors due to their poor behavior. A much, much better alternative can be found here (scroll down a bit for the actual source).
The MouseClick event from the ClickDetector object returns the player who clicked it as a parameter for the callback function. You could then check for a tool named “Hamburger” in the player’s backpack.
Use the :FindFirstChild() function to check if something that is in the player Backpack is named Hamburger
Example:
if player.Backpack:FindFirstChild("Hamburger") then
-- Function here
end
If you want to check if they have a tool named “Hamburger” that is equipped, you should do
if character:FindFirstChild(“Hamburger”) then
print(“Hamburger is equipped!”)
end
Tools that are equipped are parented to the player’s character.