Tool equip script

Hello! Im making a script so that when you click a button you will equip a tool. I started it off but I don’t know how to refer to it. But there is also another thing. I want it so that the tool is being equipped and not shown in the backpack. So your holding the tool but the tool is not in your backpack.

script

script.Parent.MouseButton1Click:Connect(function()
? -- I don't know what goes here
end)

? -- I don't know how to make it so it won't show up in your backpack

I hope you can help me! Im not the best scripture and I want to learn. I will appreciate an explanation to your script. :slight_smile:

Screen Shot 2021-04-13 at 9.04.34 AM

here are the locations. The image button I’m currently selecting is the button I want to be pressed. Knife is the tool I want to be equipped.

use humanoid equip tool : Humanoid | Roblox Creator Documentation

1 Like
script.Parent.MouseButton1Click:Connect(function()
TheHumanoid:EquipTool(YourTool)
end)

Wow four local scripts… Are you sure you need all of them? Anyway use what MrChips said and if you don’t want the backpack to show up then use SetCoreGuiEnabled to stop it from showing up.

4 local scripts are playing a big part in my game ha ha ha.

thanks! But I don’t know how to refer to “the humanoid”

1 Like

The SetCoreGuiEnabled example is a bit hard to understand. Can you explain it?

local plr = game.Players.LocalPlayer
local char = plr.Character
local humanoid = char.Humanoid

script.Parent.MouseButton1Click:Connect(function()
humanoid:EquipTool(YourTool)
end)

Ok at the bottom it gives an example and if you put that into the game it should show you all the enums. Anyway it’s just one line…

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

Set the tools parent to the player character

To make a Tool.Equipped script you might want to check out this website below for help.

If you have any problems with Tool.Equipped that should sort all your problems.

As many people have said, use Humanoid:EquipTool.

Since you were mentioning some knife,
Try to clone it from it, into the LocalPlayer’s backpack, once the button is pressed.

local plr = game:GetService("Players").LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()

local hum = chr:WaitForChild("Humanoid")

local gui = script.Parent --assuming you put the script in the gui directly

local knife = gui:FindFirstChild("Knife"):Clone()

local button = gui.Frame.ImageButton --change to whatever

button.MouseButton1Click:Connect(function()
       local knife = gui:FindFirstChild("Knife"):Clone()
       knife.Parent = plr.Backpack
end)

And since you were also asking what setcoreguienabled was,

Read up on it on here.

" This function sets whether the CoreGui element associated with the given CoreGuiType is enabled or disabled."