Making a gathering system, starting with cutting a tree through proximity prompts. Wanting to make this script make the animation stop when the player either unequips the required tool. As the script runs the 5 second animation for cutting the tree when they unequip or change tools.
I assumed the else statement would cause the script to trigger when they are not using the required “hatchet” tool.
local prompt = script.Parent
local animation = game.ReplicatedStorage.Animations.Hatchet.swing1
prompt.Triggered:Connect(function(player)
local human = player.Character:WaitForChild("Humanoid")
local loadAnimation = human.Animator:LoadAnimation(animation)
local playermodel = player.Character:WaitForChild("HumanoidRootPart")
if player.Character:FindFirstChild("Hatchet") and player.Character["Hatchet"]:IsA("Tool") then
print(player.Name, "is gathering resources.")
playermodel.CFrame = CFrame.lookAt(playermodel.Position, Vector3.new(prompt.Parent.Position.X, playermodel.Position.Y, prompt.Parent.Position.Z))
prompt.Enabled = false
human.WalkSpeed = 0
loadAnimation:Play()
wait(5)
prompt.Enabled = true
human.WalkSpeed = 18
else
player.PlayerGui.NoTool.Enabled = true
player.PlayerGui.NoTool.NoHatchet.Visible = true
print("You do not have a hatchet.")
loadAnimation:Stop()
wait(2)
player.PlayerGui.NoTool.Enabled = false
player.PlayerGui.NoTool.NoHatchet.Visible = false
end
end)
Eventually I will want to add resources to a leaderboard when people gather but for now, I’m just working on the basics of the script.