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

stop player from equipping nothing?

I'm making an fps game but at the moment a player can unequip a tool, how do I make it so the player cant unequip a tool but can change tools.

1 answer

To do this, Instead of using the Default Player Backpack, you can use replicated storage and move the tool to the character model through a script.

Local Script:

local tools = game.ReplicatedStorage.Tools --Folder in Replicated Storage called Tools
local UserInputService = game:GetService("UserInputService")
local listOfNumbers = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Zero"}

for i, v in ipairs(tools:GetChildren()) do
	UserInputService.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode[listOfNumbers[i]] then --The i is the number to be pressed to get the tool
				if game.Players.LocalPlayer.Character then
					
					if game.Players.LocalPlayer.Character:FindFirstChild("curTool") then
						game.Players.LocalPlayer.Character.curTool:Destroy()
					end
					
					local clone = v:Clone()
					clone.Name = "curTool"
					clone.Parent = game.Players.LocalPlayer.Backpack
					game.Players.LocalPlayer.Character.Humanoid:EquipTool(clone)
				end
			end
		end
	end)
end

while wait() do
	for i, v in pairs(game.Players.LocalPlayer.Backpack:GetChildren()) do
		v:Destroy()
	end
end

This is the complete Script, obviously, you should tweak it to your needs and remove the default player backpack GUI. The tools I used to test were in the Tools folder mentioned on line 1.

I don't think this is the most efficient or easy way to do this, but it's the way I found.

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