So I want to understand how to get the Character in a Script, every time I have so much trouble with this and never find a way to fix it.
Problem:
Whenever I load into the game it gives me the error: Workspace.VehicleSeat.Script:7: Attempt to index nil with 'Character’
I have looked for solutions on Youtube and the Developer Hub, and I cant find a fix, or any hints to what could be the problem.
I am trying to make a script where when you are seated on a Vehicle Seat it plays an animation.
This is the Code:
-- Variables
local PushSeat = script.Parent
local Players = game:GetService("Players")
-- Player Variables
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
-- Animation Variables
local Animation = PushSeat:WaitForChild("Animation")
local AnimationTrack = Humanoid:LoadAnimation(Animation)
Player.Seated:Connect(function()
AnimationTrack:Play()
end)
Any explanations, Hints or Help to what could be the problem would be appreciated, thank you!