Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[UNANSWERED]How do I cause tools to auto equip?

Asked by 9 years ago

I'm trying to make a custom backpack, but I can't find a function for equipping/unequipping a tool. Could someone help? If so, thanks! I think this might work:

toolInBackpack:Equip()
--and for unequipping,
toolInBackpack:Unequip()

I can't test this myself because ROBLOX Studio's Play Solo is broken.

3 answers

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

A tool becomes equipped when it's parent is a character of a player.

With this being known, you can simply change the parent of the tool to the character when you want it to be equipped and to something else when you want it to be unequipped.

Example:

-- In this example I use the player's backpack as a place to store the tool, however the tool can be stored where ever you like.

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) -- This will disable all hotkeys for selecting tools along with removing the BackpackGui.

local player = game.Players.Player
local character = player.Character
local tool = player.Backpack.Tool

function equip(tool)
    tool.Parent = character
end

function unequip(tool)
    tool.Parent = player.Backpack
end

-- Simply call equip or unequip when you wish
0
Awesome, thanks! ChipioIndustries 454 — 9y
0
No problem :) BlackJPI 2658 — 9y
0
@MastaJames, I tried to move the tools parent into the character with one of my scripts, the tool just clips through my hand. Do I need to make joints? EzraNehemiah_TF2 3552 — 9y
0
It should automatically weld onto the characters arm... BlackJPI 2658 — 9y
View all comments (2 more)
0
If not you could weld it manually, for reference on how this could be accomplished check here: http://wiki.roblox.com/index.php?title=API:Class/Tool/Grip BlackJPI 2658 — 9y
0
For some reason it works and other times it doesn't Well thanks anyway! EzraNehemiah_TF2 3552 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

Irrelevant question but does your solo crash too when you click stop and thats how its broken?

1
Actually, yeah. It says "Debugger can be attatched to a module script" ChipioIndustries 454 — 9y
Log in to vote
0
Answered by 5 years ago

https://developer.roblox.com/api-reference/function/Humanoid/EquipTool and it's counter part https://developer.roblox.com/api-reference/function/Humanoid/UnequipTools

Answer this question