I want to be able to play the animation that I’ve created, but for some reason the Animation isn’t working. It’s annexing the humanoid as nil? . . but the player is clearly there? Is it not possible to perform animations from a local script, or is there something I’m missing?
I’ve tried to look on the devforum and have looked for the proper animation syntax on the Wiki, but neither seems to help.
-- Variables --
local UserInputService = game:GetService("UserInputService")
local RemoteEvent = game.ReplicatedStorage.HardWork
Player = game.Players.LocalPlayer
Character = Player.Character
-- Function --
UserInputService.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
RemoteEvent:FireServer()
print ("Remote successfully fired.")
end
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://6929015157"
local Anim = Character.Humanoid:LoadAnimation(Track)
Anim:Play()
end)
ERROR LIST
15:31:14.617 Players.hpgames16.PlayerScripts.Melee_Local:17: attempt to index nil with ‘Humanoid’ - Client - Melee_Local:17 15:31:14.618 Stack Begin - Studio 15:31:14.618 Script ‘Players.hpgames16.PlayerScripts.Melee_Local’, Line 17 - Studio - Melee_Local:17 15:31:14.619 Stack End - Studio
I tried to do both, the first solution gave me an infinite yield, I don’t know why it’s not registering the character as nil, honestly. Here is the updated error list with the second attempt.
-- Variables --
local UserInputService = game:GetService("UserInputService")
local RemoteEvent = game.ReplicatedStorage.HardWork
Player = game.Players.LocalPlayer
Character = Player.Character
-- Function --
UserInputService.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
RemoteEvent:FireServer()
print ("Remote successfully fired.")
end
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://6929015157"
local Anim = Character.Humanoid.Animator:LoadAnimation(Track)
Anim:Play()
end)
ERROR LIST!
15:44:06.087 Players.hpgames16.PlayerScripts.Melee_Local:17: attempt to index nil with 'Humanoid' - Client - Melee_Local:17
15:44:06.087 Stack Begin - Studio
15:44:06.088 Script 'Players.hpgames16.PlayerScripts.Melee_Local', Line 17 - Studio - Melee_Local:17
15:44:06.088 Stack End - Studio
wait(1)
local UserInputService = game:GetService("UserInputService")
local RemoteEvent = game.ReplicatedStorage.HardWork
Player = game.Players.LocalPlayer
Character = Player.Character or Player.Character:Wait()
local Humanoid = Character.Humanoid
-- Function --
UserInputService.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
RemoteEvent:FireServer()
print ("Remote successfully fired.")
end
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://6929015157"
local Anim = Humanoid.Animator:LoadAnimation(Track)
Anim:Play()
end)
-- Variables --
local UserInputService = game:GetService("UserInputService")
local RemoteEvent = game.ReplicatedStorage.HardWork
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
-- Function --
UserInputService.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
RemoteEvent:FireServer()
print ("Remote successfully fired.")
end
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://6929015157"
local Anim = hum.Animator:LoadAnimation(Track)
Anim:Play()
end)
15:49:44.427 Players.hpgames16.PlayerScripts.Melee_Local:7: attempt to index nil with 'Wait' - Client - Melee_Local:7
15:49:44.428 Stack Begin - Studio
15:49:44.428 Script 'Players.hpgames16.PlayerScripts.Melee_Local', Line 7 - Studio - Melee_Local:7
15:49:44.428 Stack End - Studio
I don’t know why, but it keeps making the Character nil, doesn’t make much sense to me.
15:57:29.584 Players.hpgames16.PlayerScripts.Melee_Local:6: attempt to index nil with 'Name' - Client - Melee_Local:6
15:57:29.584 Stack Begin - Studio
15:57:29.584 Script 'Players.hpgames16.PlayerScripts.Melee_Local', Line 6 - Studio - Melee_Local:6
15:57:29.585 Stack End - Studio
Here’s the error that I’m having, it won’t even print the character or play the animation.
-- Variables --
local UserInputService = game:GetService("UserInputService")
local RemoteEvent = game.ReplicatedStorage.HardWork
local Player = game.Players.LocalPlayer
local Char = game.Players.LocalPlayer.Character
print(Char.Name)
-- Function --
UserInputService.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
RemoteEvent:FireServer()
print ("Remote successfully fired.")
end
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://6929015157"
local Anim = Char:WaitForChild("Humanoid").Animator:LoadAnimation(Track)
Anim:Play()
end)```
The code is running too fast so it doesn’t know what the RemoteEvent is
local UserInputService = game:GetService("UserInputService")
local RemoteEvent = game.ReplicatedStorage:WaitForChild("Hardwork")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
-- Function --
UserInputService.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
RemoteEvent:FireServer()
print ("Remote successfully fired.")
end
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://6929015157"
local Anim = Char:WaitForChild("Humanoid").Animator:LoadAnimation(Track)
Anim:Play()
end)