so i want a script that randomly equips a tool in your backpack is it possible?
First, you should disable the default Roblox backpack system. You can do this through SetCoreGuiEnabled
.
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
You can get the tools in a player’s backpack through :GetChildren()
, this will return a table of tools the player has in their backpack.
Using UserInputService, you detect when the player presses one of the number keys, and using math.random, we get a random key from the table. Each key representing one of the tools in player backpack.
Pseudo Code
local Tools = {
[1] = ToolX
[2] = ToolY
[3] = ToolZ
}
UserInput Service: Input Began
if input is a number key then
-- This gets a random key from the tools table
-- Min is 0, whereas max is the number of tools available
local SelectedTool = Tools[math.random(Min, Max)]
-- Since backpack is disabled, equip the player manually
--by parenting the tool to Character
SelectedTool.Parent = player Character
end
end
is this gonna be a local script or a Script, and where do i put this?
It’s a local script, as this manages the player’s backpack, this will be completely client-side.
StarterCharacter is a good place to put it so the script will continue to work even after player resets.
1 Like