Animation does not work when you click

So here I have a script, the task is to make that when you click played animation of how the player throws the bomb. And then the bomb explodes when it touches some part. Now I am doing so that the animation just played, but for some reason it does not work, why?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local bombModel = workspace["TNT STICK"]
local explosionAnimation = game:GetService("ReplicatedStorage").Throwing -- Replace 'ExplosionAnimation' with the actual name of your explosion animation

local function throwBomb()
	
	--local clone = bombModel:Clone()
	--clone.Parent = workspace
	--clone.Parent = player.Character.RightHand
	
	local Humanoid = player.Character:WaitForChild("Humanoid")
	local Animator = Humanoid:FindFirstChildOfClass("Animator")
	
	--local animation = clone:FindFirstChild("Animation") -- Replace 'Animation' with the actual name of the animation within the bomb model
	local animation = Animator:LoadAnimation(explosionAnimation)
	
	animation:Play()
	
	--clone:SetPrimaryPartCFrame(player.Character.RightHand.CFrame)
	
	print("Throw")
end



mouse.Button1Down:Connect(throwBomb)

1 Like

In the provided script, the issue seems to be with how you’re using the Animator and LoadAnimation methods. Here’s an updated version of the script that should work correctly:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local bombModel = workspace["TNT STICK"]
local explosionAnimation = game:GetService("ReplicatedStorage").Throwing -- Replace 'ExplosionAnimation' with the actual name of your explosion animation

local function throwBomb()
	local Humanoid = player.Character:WaitForChild("Humanoid")
	local Animator = Humanoid:FindFirstChildOfClass("Animator")
	
	if Animator then
		local animation = Animator:LoadAnimation(explosionAnimation)
		animation:Play()
	end
end

mouse.Button1Down:Connect(throwBomb)

In this updated version, the Animator is obtained from the player’s Humanoid instead of searching for it within the bomb model. It then checks if the Animator exists before loading and playing the animation. This should ensure that the animation plays properly when the player clicks.

Make sure to replace 'Throwing' with the actual name of your explosion animation within the ReplicatedStorage. Also, make sure that the animation is properly set up and uploaded to the game.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.