Hello
I want to put in the player’s backpack an item which must show there, but the player should not be able to activate it by keyboard or by clicking with the mouse on it.
I tried to put Enabled flag for the Tool to false, but this does nothing… When I click on the Tool, it is still highlighted and transferred from the player’s backpack to the player’s character…
What can I do?
Yes so create a tool and place in StarterPack… and give it whatever icon you want, but dont give it a Handle or any other things… it will appear in the backpack and can be selected, but nothing will happen, it will just show in backpack and character wont hold it or anything.
If you already have this tool, just delete its Handle.
My Tool does not have a handle
The problem is that when the user clicks its icon or presses “1”, the icon is still highlighted and the tool is moved out of the Player’s backpack. and I need it to stay in Player’s backpack because this is verified at some places in the game.
it shouldnt be moved out when they click on it… a script in there is doing this, so disable the script for now… right click the script and select disable.
You can always make a new tool with nothing in it literally, grab the same icon image (TextureId) from the original tool, and paste it into the new tool’s properties.
Humanoid has a function called Humanoid:UnequipTools() which unequips any tool holding.
You can make it to detect when it’s the tool that you don’t want to equip.
local tool = script.Parent
local function toolEquipped()
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
if localPlayer.Character then
local humanoid = localPlayer.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:UnequipTools()
end
end
end
tool.Equipped:Connect(toolEquipped)
I am getting error message in console:
“Something unexpectedly tried to set the parent of Tool to Backpack while trying to set the parent of Tool…”
The tool could have been attempted to be parented to the Backpack and the Character at the same time.
Can you give it a delay? (does not have to be a long delay)
Thank you
It works with wait(0.1) at the beginning of toolEquipped function
Still this is very awkward way to make a tool, which cannot be equipped.
I do not understand why “Enabled” flag does nothing…
You would just want to wait on the .Equipped event and then send it back to the players Backpack
I made a small example for this
In the client:
local tool = script.Parent -- gets the tool object
local remote = tool.Event -- gets the remote event to fire
tool.Equipped:Connect(function() -- when the tool is equipped
remote:FireServer() -- fire the server and tell it to unequip the tool
end)
In the server:
local tool = script.Parent -- gets the tool object
local remote = tool.Event -- gets the remote event to fire
remote.OnServerEvent:Connect(function(plr) -- when the client fired the event
tool.Parent = plr:WaitForChild("Backpack") -- change the tools parent to the players backpack therefor unequipping it!
end)
–we want to change the tools parent on the server so that the entire server sees it not just the client (I think, this might be worth nothing with tools, but its good practice!)
Yes, this is what is written in the help:
“It prevents the tool from being activated or deactivated by the Tool/Activate and Tool:Deactivate functions. It also prevents the Tool.Activated and Tool.Deactivated events from firing for the tool.”
However when I test, it still fires both Activated and Deactivated events when Enabled = false…
A good remark. The interesting thing is that although humanoid:UnequipTools() is called from the LocalScript I see the change also on the server (the tool is in the backpack)?