Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check if a player has a certain tool?

Asked by 6 years ago
Edited 6 years ago

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)
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 Vulkarin 581 — 6y
0
Do you know what this is? I cant open Roblox Studio, it says: Team Create reconnect fail. Unable to fetch game settings data. Alwaysrube 22 — 6y
0
No idea Vulkarin 581 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
why'd you type all that out instead of using the plr variable lol Vulkarin 581 — 6y
0
I forgot. GamingZacharyC 152 — 6y
0
I typed this in Scripting Helpers during math class. Lol GamingZacharyC 152 — 6y
Ad

Answer this question