Clicking Tool to play Animation

You can write your topic however you want, but you need to answer these questions:

  • So I’ve been trying to make a Chopping animation Play when the player Equips a tool, and Clicks anywhere on the screen. I Haven’t been able to fix it yet so any help would be helpful!

  • It’s pretty hard for me, I’m not the best scripte, but I’ve tried my best but couldnt get it working.

DevForum#1
DevForum#2
DevForum#3

local tool = script.Parent
local equippedtool = false
local animTrack = nil

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local character = player.Character or player.CharacterAdded:Wait()
	end)
end)


local Axe1 = game.ReplicatedStorage.Axe1
local Axe2 = game.ReplicatedStorage.Axe2

local can1 = true
local can2 = false

local anim1 = Instance.new("Animation")
anim1.AnimationId = "http://www.roblox.com/Asset?ID=7201386019"

local anim2 = Instance.new("Animation")
anim2.AnimationId = "http://www.roblox.com/Asset?ID=7201633002"

local canplay1 = true
local canplay2 = false


tool.Activated:Connect(function()
	if can1 == true and can2 == false then
		Axe1:FireServer()
		print("AxeAnimation1 Fired")
	elseif can1 == false and can2 == true then
		Axe2:FireServer()
		print("AxeAnimation2 Fired")
	end
end)


Axe1.OnServerEvent:Connect(function()
	print("Axe 1 Clicked")
	canplay1 = false
	canplay2 = true
	animTrack = character.Humanoid:LoadAnimation(anim1)
	animTrack:Play()
end)


Axe2.OnServerEvent:Connect(function()
	print("Axe 2 Clicked")
	canplay2 = false
	canplay1 = true
	animTrack = character.Humanoid:LoadAnimation(anim2)
	animTrack:Play()
end)

Only help, if you have time, I don’t wnana waste anyones time! :slight_smile:

Steps:

  1. You have to use local script if you want to run :FireServer()
  2. :FireServer() sends a signal to the server, meaning that there is no use if you send a signal from the server, to the server-
1 Like

You don’t have to play the animation from the server, You could just do this.

local tool = script.Parent
local animTrack = nil

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local anim1 = Instance.new("Animation")
anim1.AnimationId = "http://www.roblox.com/Asset?ID=7201386019"
anim1.Parent = tool

local anim2 = Instance.new("Animation")
anim2.AnimationId = "http://www.roblox.com/Asset?ID=7201633002"
anim2.Parent = tool

local track = 1

tool.Activated:Connect(function()
	if track == 1 then
		animTrack = character.Humanoid:LoadAnimation(anim1)
		animTrack:Play()
		track += 1
 	else
		animTrack = character.Humanoid:LoadAnimation(anim2)
	 	animTrack:Play()
	 	track = 1
	end
end)

I didn’t test it yet.

1 Like

Sorry, Just found that out after posting this!

Doesn’t work, Imma try to find the issue

If there’s any output error, please send a screenshot.

1 Like

image
This is the only errors I get.

Oh oh, change this script
image
to local script

1 Like

Holy mate, It works! Thanks!
Have a great day!

1 Like

just a quick question, How do I make so I can’t spam the Animation with Spam clicking?

You can use debounce.

1 Like

Sorry to bother, but I don’t know how to add Debounces here!

Uh oh, just do this.

local track = 1
local debounce = false

local debounce_time = 1 -- seconds

tool.Activated:Connect(function()
	if debounce then
		return
	end
	
	debounce = true
	
	if track == 1 then
		animTrack = character.Humanoid:LoadAnimation(anim1)
		animTrack:Play()
		track += 1
	else
		animTrack = character.Humanoid:LoadAnimation(anim2)
		animTrack:Play()
		track = 1
	end
	
	wait(debounce_time)
	
	debounce = false
end)
1 Like

Thanks mate! You’re a nice guy

1 Like