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.
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)
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
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
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