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

How to check if a player has a certain tool?

In my current script when you click a certain block of a tree the rest falls down, How can I get it so only when you have a tool with the name "Axe" you are able to harvest the tree? I have been trying a lot of things but nothing works.

wait(2)
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character
local x = script:FindFirstChild("Wood")

local GetWood = true

function ShowProgress(tree)
	if tree == 'SmallTree1' then
		for i = 0,1,.01 do
			WC.BG.Progress.Size = UDim2.new(i,0,1,0)
			wait()
		end
	elseif tree == 'MediumTree' then
		for i = 0,1,.005 do
			WC.BG.Progress.Size = UDim2.new(i,0,1,0)
			wait()
		end
	end
end
	
mouse.Button1Down:connect(function()
	if mouse.Target ~= nil and mouse.Target.Parent.Name == 'SmallTree1' and GetWood == true then
		local Wood = mouse.Target		
    if (Wood.position - char.UpperTorso.position).magnitude < 10 then
			GetWood = false
			WC = plr.PlayerGui.WoodChopper
			WC.BG.Visible = true
			ShowProgress('SmallTree1')
			for i,v in pairs(Wood.Parent.Leaves:GetChildren()) do
				if v:IsA('Part') then
					v.Anchored = false
				end
			end
			for i,l in pairs(Wood.Parent.Logs:GetChildren()) do
				if l:IsA('Part') then
					l.Anchored = false
				end
			end
			Wood:Destroy()
			WC.BG.Visible = false
			GetWood = true
		end
	end																		
end)

3 comments

0

if plr.Backpack:FindFirstChild("Axe"), but I would note to you that since this is a localscript the stuff you are doing will not replicate (i.e.: Unanchoring a part). You need to use remote events

0

Do you know what this is? I cant open Roblox Studio, it says: Team Create reconnect fail. Unable to fetch game settings data.

0

No idea

1 answer

✓ Accepted answer

So, you would need to access the players' backpack, which will be easy since this is a LocalScript.

wait(2)
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character
local x = script:FindFirstChild("Wood")

local GetWood = true

function ShowProgress(tree)
	if tree == 'SmallTree1' then
		for i = 0,1,.01 do
			WC.BG.Progress.Size = UDim2.new(i,0,1,0)
			wait()
		end
		elseif tree == 'MediumTree' then
			for i = 0,1,.005 do
			WC.BG.Progress.Size = UDim2.new(i,0,1,0)
			wait()
		end
	end
end

mouse.Button1Down:connect(function()
	if game.Players.localPlayer.Backpack:FindFirstChild("Axe")
		if mouse.Target ~= nil and mouse.Target.Parent.Name == 'SmallTree1' and GetWood == true then
			local Wood = mouse.Target       
			if (Wood.position - char.UpperTorso.position).magnitude < 10 then
				GetWood = false
				WC = plr.PlayerGui.WoodChopper
				WC.BG.Visible = true
				ShowProgress('SmallTree1')
					for i,v in pairs(Wood.Parent.Leaves:GetChildren()) do
						if v:IsA('Part') then
						v.Anchored = false
					end
				end
				for i,l in pairs(Wood.Parent.Logs:GetChildren()) do
					if l:IsA('Part') then
						l.Anchored = false
					end
				end
				Wood:Destroy()
				WC.BG.Visible = false
				GetWood = true
			end
		end
	end                                                                  
end)

NOTE: I DID NOT FIX/CHANGE ANYTHING WITH THE SCRIPT OTHER THAN ADD THE TOOL FINDER.

3 comments

0

why'd you type all that out instead of using the plr variable lol

0

I forgot.

0

I typed this in Scripting Helpers during math class. Lol

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