Animation won't fire

  1. What do you want to achieve? When you click, the animation will play accordingly.

  2. What is the issue? The animation won’t fire and there is no errors.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Tool = script.Parent
local userInputServ = game:GetService("UserInputService")
local Event = game:GetService("ReplicatedStorage"):WaitForChild("Test")

local Animation = Tool.Animation

local Connection = nil

local lastChatMessage = nil

local raycastParams = RaycastParams.new()

raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {Player.Character, Tool}


Tool.Equipped:Connect(function()
	Connection = userInputServ.InputBegan:Connect(function(input, gpe)
		if gpe then return end
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			if not lastChatMessage or lastChatMessage == nil then print("c") return end
			local ray = workspace:Raycast(Player.Character.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.CFrame.lookVector * 7.5, raycastParams)
			if not ray or ray == nil then print("b") return end
			Player.Character.Humanoid:LoadAnimation(Animation):Play()
			if #lastChatMessage:split("|") ~= 2 then return end
			Event:FireServer(ray.Instance.Parent.Name, lastChatMessage)
		end
	end)
end)

Tool.Unequipped:Connect(function()
	if typeof(Connection) == "RBXScriptConnection" then
		Connection:Disconnect()
	end
end)

Player.Chatted:Connect(function(message)
	lastChatMessage = message
end)```


Thanks.
AtlasType
1 Like

LoadAnimation is deprecated although deprecated things just dont get broken but still this might fix your issue:

When a player joins use Instance.new(“Animator”, player.Character.Humanoid) on them then on the client when your character loads you can use local anim = game.Players.LocalPlayer.Character.Humanoid:WaitForChild(“Animator”) then use local realanim = anim:LoadAnimation(Animation) at the start of your script then you can use realanim:Play() whenever you want

edit: use Instance.new(“Animator”, player.Character.Humanoid) on server and use local anim = game.Players.LocalPlayer.Character.Humanoid:WaitForChild(“Animator”) on client