Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do i equip a tool from a menu?

so i'm experimenting right now to make a game and i have an inventory gui. i have a button that is supposed to move the tool into starter pack but i have a custom backpack, here is the script for it :

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

local plr = game.Players.LocalPlayer
local char = plr.Character
local UIS = game:GetService('UserInputService')
local equipped = false 

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.R then
		if equipped == false then 
			char.Humanoid:EquipTool(plr.Backpack:WaitForChild('ClassicSword'))
			equipped = true
		else
			equipped = false
			char.Humanoid:UnequipTools()
		end
	end
end)

I have the tool as a child in the inventory gui and i made a script so when you click it it moves the tool to starter pack, here is the script :

local slot1 = script.Parent.slot1
local sword = script.Parent.ClassicSword

slot1.MouseButton1Click:connect(function()
	sword.Parent = game.StarterPack
end)

It moves the tool to the starterpack, but when i press R it doesn't equip. any help?

3 comments

0

You would want to fire a remote event

0

And fire server to move the sword to starterpack.

1 answer

StarterPack only clones items in it into the player’s backpack when the player joins/respawns. Also note that StarterPack affects ALL players.

For players that didn’t respawn/join when the item is added to StarterPack, they can’t equip it because the item isn’t in their Backpack yet, so that :WaitForChild() you added there is going to stall forever until the player resets.

The way I would fix and do this is to make a folder in the player and name it “CustomBackpack” or whatever. I would then clone the sword to that folder instead of putting it in StarterPack where everyone can get it. You can then make your script find the sword in the folder and use :EquipTool() on it.

Hoped this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.