Indexing nil with character

I have a car buying and spawning system, that, when a car is spawned, it teleports the player to the car’s VehicleSeat. However, my local Character value seems to have something wrong with it. Here is the error:

Portion of script with error:

local players = game:GetService("Players")
local Character = players.LocalPlayer.Character -- This is where the error is coming from.

Is this a serversided script? You can’t get local player from the server.

2 Likes

LocalPlayer does not exist on the server.

1 Like

Try to write

wait (1/60)
before it

That doesn’t matter, local player cannot be referenced by the server. Only the client.

1 Like

Player.LocalPlayer only works in LocalScripts so in order to get someone’s Character in server for some reason you can create a RemoteEvent and use RemoteEvent.OnServerEvent event in ServerScript and RemoteEvent:FireServer() function in LocalScript.

3 Likes

Whoops! Thanks for pointing that out.

Did he say that it’s local script? I’m said it if it’s server sided script.
nvm

I mean in error it says ServerScriptService so it can’t be a LocalScript.

It is a serverscript. You can tell form the error in output.
EDIT: Ben beat me to saying this

1 Like

According to the color of the message (green), this was done in a ServerScript and not a LocalScript(blue)

You cannot get LocalPlayer on the server as that Accounts for every player and not just one client

1 Like

When did I say that it’s local script lol? In my first reply I told what to do if it’s server sided script. But I didn’t say that it’s local or server script