I have a gui and a button when i click the button it should equip the tool in my backpack but if its already equipped then it haves to unequip. But i dont know why the script doesnt work can someone send me the correct script?
1 Like
No it should be Players.LocalPlayer not Player in line 2.
I think. Can be wrong though.
Let’s start at the beginning. It seems like your Player in line two have some issue.
Most likely unknown variable.
Backpack.Tool.Equipped on line 6 and 9 is an event. So it does nothing.
To solve your problem.
You need to check out the humanoid API where it mentions the function “EquipTools” and “UnequipTools”.
That should give you enough hints to solve your problem.
2 Likes
what’s the error you get in the output?
local plr = game.Players.LocalPlayer
local Bp = plr.Backpack
local Btn = script.Parent
local Tool = --Tool location here
Btn.MouseButton1Click:Connect(function()
if plr and Bp and Tool then
if Bp:FindFirstChild("ToolNameHere") then
Bp.ToolNameHere:Destroy()
elseif Bp.ToolNameHere ~= true then
local NewTool = --location
NewTool.Parent = plr.Backpack
local Newtool2 = --location
Newtool2.Parent = plr.StarterGear
end
end
end
end)
3 Likes
use humanoid:EquipTools({tool})