Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

ServerScriptService

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

while wait() do
    player2.WalkSpeed = 16 + player.leaderstats.Cash.Value
end
0
If this is a local script, why is it in ServerScriptService? echobloxia 21 — 2y
0
It's a regular one. MustardKingRules 2 — 2y

3 answers

Log in to vote
0
Answered by 2 years ago

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.

0
It's still giving out the same error. MustardKingRules 2 — 2y
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 PaleNoobs 37 — 2y
0
Character is not a valid member of RBXScriptSignal (line 2), am I missing something? MustardKingRules 2 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

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

local player2 = player.Character.Humanoid

Try using:

local player2 = player.Character:WaitForChild('Humanoid')
0
It's still giving out the same error. MustardKingRules 2 — 2y
Log in to vote
0
Answered by 2 years ago

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.

Answer this question