About using a a button to equip a tool

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    when the player clicked the button it equips their tool
  2. What is the issue? Include screenshots / videos if possible!
    well i have it sort of working like it shows its been clicked but no tool equips nor unequips
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i’ve been looking for solutions on here and on google

How about you put your script here, since you’re asking for scripting help.
You can also search developer.roblox.com to find out a lot about Roblox stuff.
print("...stuff...") statements can be used in your script to pinpoint what’s happening in your Output window.
Also a picture of your Explorer window with the way your button and script are placed, as well as any items that are called for in your script. For example if you have button = script.Parent.Parent.ButtonPart.ClickDetector then is the ClickDetector actually a child of the ButtonPart which is a child of the item the script is in?

You could achieve that by using Humanoid:EquipTool(yourtool)

And to unequip it (if you need it) you could of course use Humanoid:UnequipTools()

I guess you know how to connect those with your Click Event.

If you don’t, the way to do it with a ClickDetector is by using the ClickDetector.MouseClick event

example:

local tool = your tool basically
local detector = your click detector

detector.MouseClick:Connect(function(player)
local humanoid = player.Character.Humanoid

humanoid:EquipTool(tool)
end)
1 Like

this it what i use for the button, for it to show the button, and for it to equp the tool

local player = game.Players.LocalPlayer
local toolequipped = false
local button = script.Parent

script.Parent.MouseButton1Click:Connect(function()
	if toolequipped == false then
		if player and player.Character then
			local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				local tool = player.Backpack.Punch
				if tool then
					humanoid:EquipTool(tool)
					toolequipped = true
					button.Image = "rbxassetid://8719690992"
				end
			end
		end
	elseif toolequipped == true then
		if player and player.Character then
			local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				local tool = player.Backpack.Punch
				if tool then
					humanoid:UnequipTools(tool)	
					toolequipped = false
					button.Image = "rbxassetid://8719666363"
				end
			end
		end
	end

end)

when i equip the tool it then goes into the workspace and not where it was before

tool.Parent = player.Backpack or player.Character
--if you want it to go in their backpack or character then delete the other one
---like if you want the tool to be equipped when they get it give it to their character
--but if not then parent it to the player's backpack

Yeah like when it’s not equipped it’s in the players>playername>backpack, but once it’s equipped it then goes to the workspace.playername

when it goes to workspace>plr.Name that is normal, since the model with the players name is its character

Oh thanks, that would explain it, I’ll give it a shot

pls make mine the solution if it works :pleading_face:

Also use button.Activated instead of button.MouseButton1Click so mobile players can use the button as well.

Oh I see that would come in handy

if i use

tool.Parent = player.Character

i then cant unequip

but if i use

player.Backpack

then its like nothing is there

I fixed it, when I tested it it worked for me

local player = game.Players.LocalPlayer
local toolequipped = false
local button = script.Parent

script.Parent.MouseButton1Click:Connect(function()
	if toolequipped == false then
		if player and player.Character then
			local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				local tool = player.Backpack.Punch
				if tool then
					humanoid:EquipTool(tool)
					toolequipped = true
					button.Image = "rbxassetid://8719690992"
				end
			end
		end
	elseif toolequipped == true then
		if player and player.Character then
			local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
			if humanoid then
				if player.Character:FindFirstChildOfClass("Tool") then
					humanoid:UnequipTools(player.Character:FindFirstChildOfClass("Tool"))	
					toolequipped = false
					button.Image = "rbxassetid://8719666363"
				end
			end
		end
	end

end)
2 Likes

oh snap your right it does work

Thanks :innocent: (char limit) (more char limit)