Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index nil with 'Character' (at line 2)?

ServerScriptService

local player = game.Players.LocalPlayer
local player2 = player.Character.Humanoid

while wait() do
	player2.WalkSpeed = 16 + player.leaderstats.Cash.Value
end

2 comments

0

If this is a local script, why is it in ServerScriptService?

0

It's a regular one.

3 answers

You should give the game a few seconds to load the character. It shows as nil because the character probably hasn't loaded in yet. Try adding a wait(2) at the beginning of your script.

3 comments

0

It's still giving out the same error.

0

I found your issue! You can't use LocalPlayer in a server script. You need to get the player using another method like an event. Here's an example of an event you could use: game.Players.PlayerAdded

0

Character is not a valid member of RBXScriptSignal (line 2), am I missing something?

The humanoid probably has not loaded in yet, instead of using:

local player2 = player.Character.Humanoid

Try using:

local player2 = player.Character:WaitForChild('Humanoid')

1 comment

0

It's still giving out the same error.

The problem is you're using LocalPlayer in a serversided script. LocalPlayer is only available for LocalScripts, so convert your serversided script into a local script and you'll be fine.

This discussion is preserved as it was. New answers, comments, and votes are closed.