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

about equiping tools and you cant unequip. theme in description Name?

Theme Name .equip a tool from backpack any you want but you cant unequip tools you need to have 1 equiped like FPS games.? so i did LocalScript that player equips a tool if its in a somewhat spot 1,2,3,4,5,6 if the guy unequips the gun it equips again but it loads like later 1 seconds so i dont want that can someone say me what to do? thats what i did.

local p = game.Players.LocalPlayer
local UI = game:GetService("UserInputService")
local chr = player.Character

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

UI.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.One then
		chr.Humanoid:UnequipTools()
		chr.Humanoid:EquipTool(p.Backpack:WaitForChild("Glock 18"))
	end
end)


1 comment

0

Your grammar is a bit hard to read, are you asking to make the gun always be equipped and be unable to be removed?

1 answer

✓ Accepted answer

Well from what I can see, the script works fine, except that the "p" and "player" are both the same variable, but only "p" is called. What you need to do is make sure all variables are defined before calling them. You can do this by editing their names like so:

local player = game.Players.LocalPlayer
local UI = game:GetService("UserInputService")
local chr = player.Character
 
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

UI.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.One then
		local original = chr:FindFirstChildOfClass("Tool")
		local gun = chr:FindFirstChild("Glock 18")
		if original == nil then
			chr.Humanoid:EquipTool(player.Backpack:WaitForChild("Glock 18"))
		elseif original ~= nil and gun == nil then
			chr.Humanoid:UnequipTools()
			chr.Humanoid:EquipTool(player.Backpack:WaitForChild("Glock 18"))
		end
	end
end)

I simply edited the name of p to be player. However, I should note that the way your script is written means that the change in the player's weapon will only occur for the single client (no other players will see the change) since it is in a LocalScript EDIT: Alright, so I added this clause to prevent re-equipment of the tool. The event "FindFirstChildOfClass" makes sure that a child of that class is either not already in the humanoid, and if it is then the function will remove the previous tool.

3 comments

0

yea but can you say one more thing? how to make it that if he has equipped a 1 gun and he cant equip tool 1 again i mean requip

0

You don't "call" a variable.

0

@MrLordFear, sure give me a sec

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