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

can someone help me figure out why my code dosent play the animation when i click?

local UserInputService = game:GetService("UserInputService") local Animation = script.Parent

UserInputService.InputBegan:Connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then local Player = game.Players.LocalPlayer local Character = Player.Character local Humanoid = Character:WaitForChild("Humanoid")

	local Anim = Humanoid:LoadAnimation (Animation)
	Anim:Play()
end

end)

FYI the animation is under the local script

1 answer

✓ Accepted answer

I decided to copy your code and put an Animation object in StarterPack then put a LocalScript inside the Animation object, after doing this I pasted your code into the local script and everything worked fine, animation played, no errors. I recommend you check if the Animation object you have has an ID in it if not then that may be the problem. Otherwise the animation provided is different from the character type you have in your game, for instance your game's character type is r6 but the animation is for r15 then that animation will not work for your game. Also make sure the local script you have is under StarterPack, StarterCharacterScripts or StarterPlayerScripts. Here's your script I copied if wondering.

local UserInputService = game:GetService("UserInputService")
local Animation = script.Parent

UserInputService.InputBegan:Connect(function(InputObject)
	if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
		local Player = game.Players.LocalPlayer
		local Character = Player.Character
		local Humanoid = Character:WaitForChild("Humanoid")
		
		local AnimationTrack = Humanoid:LoadAnimation(Animation)
		AnimationTrack:Play()
		
	end
end)

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