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

Why does this tree chop script not work? (I made it, probably why :P)

Asked by 6 years ago
local debounce = false
local a = script.Parent      
local b = script.Parent.Log
local c = script.Parent.Log2
local d = script.Parent.Log3
local e = script.Parent.Log4
local f = script.Parent.Leaves
local g = script.Parent.Leaves2
local h = script.Parent.Leaves3
local i = script.Parent.Leaves4
local hits = 0 
local hitsneeded = 4 
b.Touched:connect(function(hit) 
    if not debounce then
        debounce = true
        debounce = false
      end 
    if hit.Parent.Name == "Basic Axe" then 
        hits = hits + 1 

        if hits == hitsneeded then 
            hits = 0 
            b.Anchored = false 
            c.Anchored = false
            d.Anchored = false
            e.Anchored = false
            f.Anchored = false
            g.Anchored = false
            h.Anchored = false
            i.Anchored = false
            f.CanCollide = false
            g.CanCollide = false
            h.CanCollide = false
            i.CanCollide = false
        end
    end
end)


The tree should fall once it reaches 4 hits, but it falls on the first hit which i touch it with the Basic Axe. I was told to add a debounce so I did, still the same thing happens. If I put the "debounce = true" line after the "hits = hits + 1" line, the whole script fails to work and the tree doesn't fall at all. Maybe it's not a problem with the debounce, maybe the script has a problem with the hitsrequired variable and just follows the rest of the script causing the tree to fall?

0
You dont have a wait statement in your wait function. It will go to 4 imeadiatly without waiting. Timmerman73 85 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

If you're using a debounce, you wanna make it look something like this:

local debounce = false
local a = script.Parent      
local b = script.Parent.Log
local c = script.Parent.Log2
local d = script.Parent.Log3
local e = script.Parent.Log4
local f = script.Parent.Leaves
local g = script.Parent.Leaves2
local h = script.Parent.Leaves3
local i = script.Parent.Leaves4
local hits = 0 
local hitsneeded = 4 
b.Touched:connect(function(hit) 
    if not debounce then
        if hit.Parent.Name == "Basic Axe" then
        debounce = true
        hits = hits + 1
            if hits >= hitsneeded then 
                hits = 0 
                b.Anchored = false 
                c.Anchored = false
                d.Anchored = false
                e.Anchored = false
                f.Anchored = false
                g.Anchored = false
                h.Anchored = false
                i.Anchored = false
                f.CanCollide = false
                g.CanCollide = false
                h.CanCollide = false
                i.CanCollide = false
            end
        wait(1) -- You can change this to the time between each axe swing
        debounce = false
    end
    end
end)

I may be wrong, please correct me if I am. Have fun scripting!

Ad

Answer this question