Animation is not playing with gui

So I am trying to make a billboard GUI with a button that when it is clicked it does plays an animation.
The problem is that when I click the gui button nothing happens
When I run the game, studio tells me

attempt to index nil with ‘Character’

I started with using local script in the workspace but nothing happened.
Here is my local script that is in the Workspace

local Players = game:GetService("Players")

local player = Players:FindFirstChild("Builderman")

local character = player.Character 
local humanoid = character:FindFirstChild("Humanoid")


script.Parent:WaitForChild("TextButton").MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)

And here is my server script that is in ServerScriptService

local Players = game:GetService("Players")

local player = Players:FindFirstChild("Builderman")
local character = player.Character 
local humanoid = character:FindFirstChild("Humanoid")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://6514151923" 
local animator = humanoid:FindFirstChildOfClass("Animator")
local animTrack = animator:LoadAnimation(animation)



game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
	print("Clicked")
	animTrack:Play()
end)

I am new to animating.
Any help would be appreciated.

Studio still shows me this error
attempt to index nil with ‘Character’

Here is the code you gave my I put in my server script in the workspace:

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local character = player.Character or player.CharacterAdded:Wait()

local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")

animation.AnimationId = "rbxassetid://6514151923"

local animator = humanoid:FindFirstChildOfClass("Animator")

local animTrack = animator:LoadAnimation(animation)

script.Parent:WaitForChild("TextButton").MouseButton1Click:Connect(function()

animTrack:Play()

end)

load animation on humanoid
try :
humanoid:LoadAnimation(animation)

Studio still tell me attempt to index nil with ‘Character’

Here is my code it is a server script in the workspace.

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local character = player.Character --or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://6514151923" 
local animator = humanoid:FindFirstChildOfClass("Animator")
local animTrack = humanoid:LoadAnimation(animation)

script.Parent:WaitForChild("TextButton").MouseButton1Click:Connect(function()
	animTrack:Play()
end)

that means it think humanoid doesnt exist on the character, try doing character.Humanoid or replace it with FindFirstChild(“Humanoid”) this always happens to me so i fixed it by doing that

is that a server script or a local script?

if it’s a server script, change it to a local script

1 Like

Again, LocalPlayer does not work in Server scripts, try putting the Billboard gui in StarterGui and setting t he Adornee of it to wherever part it should be connected to? Again, convert it to a Localscript as well

1 Like

like they said, move all the animation thing to a serverscript and put the MouseButton1Click
on a local script

don’t make the humanoid load an animation

just replace
local animTrack = humanoid:LoadAnimation(animation)
with
local animTrack = animator:LoadAnimation(animation)

pretty sure making the humanoid load an animation is deprecated

I set the adornee to the part and changed the script to a local script

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local character = player --or player.CharacterAdded:Wait()

local humanoid = character:FindFirstChild("Humanoid")

local animation = Instance.new("Animation")

animation.AnimationId = "rbxassetid://6514151923"

local animator = humanoid:FindFirstChildOfClass("Animator")

local animTrack = humanoid:LoadAnimation(animation)

script.Parent:WaitForChild("TextButton").MouseButton1Click:Connect(function()

animTrack:Play()

end)

Studio tells me

attempt to index nil with ‘FindFirstChildOfClass’ - Client - LocalScript:10

local character = player --or player.CharacterAdded:Wait()

local humanoid = character:FindFirstChild("Humanoid")

Change these to

local character = player.Character or player.CharacterAdded:Wait()

local humanoid = character:WaitForChild("Humanoid")
1 Like

It works thanks so much I was working on this for a long time!

1 Like