Please excuse me if this isn’t the correct place, or if I’ve forgotten to include something! This is my first post! 
-
What do you want to achieve?
I am trying to create a simple tree chopping system. I am unsure of how to decrement the tree’s “HP” while the player is interacting with the proximity prompt, and their axe has hit the tree.
-
What is the issue? Include screenshots / videos if possible!
Screen Recording 2021-01-13 at 5.47.23 PM
-
What solutions have you tried so far?
I am currently using a local script inside of StarterPlayerScripts
to handle the ProximityPrompt’s triggered and untriggered events. I then have a remote event inside of ReplicatedStorage
which is handled by a regular script inside of ServerScriptService
. This script to handle the actual tree damaging is below. As you can imagine, it’s a mess and doesn’t work.
remotesFolder.chop.OnServerEvent:Connect(function(player, animationLength)
if player.Character then
local axeInformation = findAxeFromCharacter(player.Character);
print(axeInformation.Value);
local axe = player.Character:FindFirstChild(axeInformation.Name);
local debounce = false;
axe.Blade.Touched:Connect(function(partTouched)
local tree = partTouched.Parent;
local treeInformation = treeInformationHandler.getTreeInformation(tree.Name);
if treeInformation and not debounce then
debounce = true;
treeInformationHandler.chop(axeInformation.HitPoints, tree);
print("Chopped tree");
wait(animationLength);
debounce = false;
end
end)
end
end)
How would any of you go about creating a system like this? I think my biggest confusion is not knowing when to handle something on the client/server and how to handle it.
1 Like
I believe you should listen for these events on server-sided, NOT client-sided. That may be the issue.
1 Like
Thank you for responding! I went ahead and tried that approach. I’m now facing the issue of the animation not looping. I was originally basing the damage function on when the axe makes contact with the tree via a touched function, but if the animation isn’t looping then it only hits the tree once. Is there a better approach to this? I’ve included a video of the animation problem as-well!
https://streamable.com/jkm33n
These functions are called when the ProximityPrompt is triggered and untriggered. (dis-triggered?)
local onTriggered = function(player)
print(player.Name.." began chopping down a tree!");
if player.Character then
local animation = Instance.new("Animation");
animation.AnimationId = "rbxassetid://"..6222766141;
animation.Name = "swingAnim";
local swingAnim = player.Character:FindFirstChildWhichIsA("Humanoid"):LoadAnimation(animation);
loadedAnimationsTable["swingAnim"] = swingAnim;
swingAnim.Looped = true;
swingAnim:Play()
--player.Character.HumanoidRootPart.Anchored = true;
end
end
local onTriggerEnded = function(player)
print(player.Name.." stopped chopping down a tree!");
local swingAnim = loadedAnimationsTable["swingAnim"];
swingAnim:Stop();
--player.Character.HumanoidRootPart.Anchored = false;
end```
1 Like
Humanoid:LoadAnimation() is now deprecated, use Animator, a child of the humanoid, to Animator:LoadAnimation() instead.
1 Like
Thank you for pointing that out! I’ve went ahead and made those changes but the new problem of the animation not looping, and subsequently not being able to figure out a way to handle the actual axe-has-touched-a-tree part is still what I’m trying to figure out.
Like I said previously, I’m unsure if there’s a better approach to figuring out when the axe has touched a tree besides a touched event. 
1 Like