I want to make it where it plays a animation on click and it is not playing it.
No errors are popping up in output.
Animation Is Still A Part Of Tool:
Code:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Button1Down = mouse.Button1Down
local Players = game:GetService(“Players”)
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
Button1Down:Connect(function(swing1)
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.animation)
end)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Character = player.Character or player.CharacterAdded:Wait()
mouse.Button1Down:Connect(function()
local animation = Character.Humanoid:LoadAnimation(script.Parent.animation)
animation:Play()
end)
For future reference, indent your code and put them in code blocks ``` (these things).
Looking at your code, there’s several problems.
For one thing, you should use your Character variable when loading the animation and do it outside of the function.
Now your main problem is you’re not actually playing the animation and Button1Down should be Mouse.Button1Down
local Character = LocalPlayer.Character
local animation = Character.Humanoid:LoadAnimation(script.Parent.animation)
Mouse.Button1Down:Connect(function(swing1)
animation:Play()
end)
I would implement adding print statements then to check what runs and what doesn’t:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Character = player.Character or player.CharacterAdded:Wait()
mouse.Button1Down:Connect(function()
print("Mouse fired")
local animation = Character.Humanoid:LoadAnimation(script.Parent.animation)
animation:Play()
print("Animation playing")
end)
Also, make sure the animation body type is valid to what your rig body type is (R15 animation should be an R15 body)
um i was reading the dev hub on the Humanoid:LoadCharacter() is deprecated. mentioned here so maybe try using another method of playing animation like animation controller maybe?
oh yeah sorry I misspelled that, i meant to say “LoadAnimation” but nice catch.
LoadCharacter is function of the player not the character’s humanoid. eek