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

How come when I put a animation in a tool and make it to where it Plays nothing happens?

Asked by
Prioxis 673 Moderation Voter
9 years ago

I made a axe and my function that gets called later to play the animation nothing happens when it gets called nothing happens

function hit()
    local anim = script.Parent.Anim
end

The error

disconnected event because of exception

will someone please help me full script here

wait(1)
------------------------
axelvl = 2 --This is the damage given to the tree.
treeMoney = 15 --this is how much money you get for felling a tree
resettime = 2 --this is how long it takes after the axe hit a tree until it works again. Avoid setting it to 0
------------------------

Tool = script.Parent
ting = 0 --this is my debounce

function hit()
    local anim = script.Parent.Anim
end

function onActivated() 
    if not Tool.Enabled then
        return
    end

    Tool.Enabled = false
    hit()
    Tool.Enabled = true

end 

function onTouched(hitt)
--  print("touched something")
    if ting == 0 then
    ting = 1
    if hitt.Parent.Name == "Tree" then
--  print("touched tree")
    user = game.Players:findFirstChild(Tool.Parent.Name) --find the player that carries the axe for later moneygiving

    hitt.Parent.hit.Value = hitt.Parent.hit.Value - axelvl --deal damage to the tree 
    hitt.Parent.Timber.Value = hitt.Parent.Timber.Value - axelvl
    if hitt.Parent.hit.Value < 1 and hitt.Parent.Timber.Value < 1 then --check if the tree is felled
        user.leaderstats.Wood.Value = user.leaderstats.Wood.Value + treeMoney --add money to the dude with the axe
        hitt.Parent.Timber.Value = 1 --this declares the tree "felled" and makes sure nobody else can get money from it
        wait(resettime)
    else
        wait(1)
    end
    end
    ting = 0
    end
end

Tool.Activated:connect(onActivated)
connection = Tool.Handle.Touched:connect(onTouched)

1 answer

Log in to vote
-6
Answered by 9 years ago

Not sure onTouched has only 1 capital in it, I believe it is either ontouched or OnTouched. Also little thing useful in tools, check that the tool was activated (mouse click) before starting all the calculations, and your indentation for the IF after ting is to lower, it needs to be 1 higher, just so its easier to understand.

But im not sure otherwise where your problems might lie

0
The name of a function doesn't matter, as long as it is called by the same name consistently. adark 5487 — 9y
0
Last time I checked their were several instances where sometimes the function used capital and sometimes didnt depending on what its contained in. spike43884 -2 — 9y
Ad

Answer this question