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

Tree Cutting Script Question?

Asked by 5 years ago

Hello! I am currently fairly new to scripting and need some help with a game I'm trying to develop. I've created a script to cut down trees with a certain tool but it's a Touched function, so even if the ace touches the tree without the player clicking with the axe to play the swing animation they still deal damage to the tree. I have the tree set to a numbervalue(health) of 100 and the Touched script makes it decrease by 10 everytime it touches the tree, but the problem is that even if the axe the player is holding touches the tree it still deals damage. Is there any other easier way to make it so that the player only deals damage if they click with the axe?

1 answer

Log in to vote
0
Answered by
blockmask 374 Moderation Voter
5 years ago

Sure, also I made a game like this, which is this makes it easier for me to help you. You can used the activated event to set a variable to true if the player is clicking while equipping the tool. Example:

local axe = script.Parent--tool
local blade = axe:WaitForChild("Blade")
local swingingAnimation = (animation_Path)
local swinging = false

local function activated()
    swinging = true
    delay(.3,function()--turns swinging to false just so they can't glitch damage
        swinging = false
    end)
    local humanoid = axe.Parent:FindFirstChild("Humanoid")
    if humanoid then
        --play animation
    end
end
axe.Activated:Connect(activated);

blade.Touched:Connect(function(hit)
    if swinging then
        swinging = false
        --tree damage
    end
end)

This script basically says if the player is swinging, and the blade is touched then it will turn swinging into false, and then it will procceed to do the tree damage script.

Ad

Answer this question