Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My animation code is not working and there are no errors, how can I fix this?

--Services
local Players = game:GetService("Players")

--Modules
--Constants
local Character = script.Parent
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Player = Players:GetPlayerFromCharacter(Character)

--Variables
local CurrentTool
local CurrentFunc

--Functions
--Main
Character.ChildAdded:Connect(function(o)
	if o:IsA("Tool") then
		CurrentTool = o
		if CurrentFunc then CurrentFunc:Disconnect() end 
		local Animations = o:FindFirstChild("Animations")
		if Animations then
			local TestAnimation = Animations:FindFirstChild("Main")
			if not TestAnimation then return end  
			CurrentFunc = o.Activated:Connect(function()
				local Test = Humanoid:FindFirstChildOfClass("Animator"):LoadAnimation(TestAnimation)
				Test:Play()
			end)
		end
	end
end)

1 answer

✓ Accepted answer

Make sure your "Tool" have a handle

If not then turn "requirehandle" property to false

Also if a script not giving any error, i suggest using the print function to see where the script manage to go through and where it didnt

This discussion is preserved as it was. New answers, comments, and votes are closed.