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

attempt to index global 'plr' (a nil value)?

Hi, i was running a script to fire event if player have 100 calls in leadstats. plrs = game:WaitForChild("Players")

1	 plrs = game:WaitForChild("Players")
2  plr = plrs.LocalPlayer
3   
4   if plr.leadstats.Calls.Value == 99 then
5    
6    
7	game.ReplicatedStorage.StrengthEvent.OnServerEvent:Connect(function(player)
9    player.PlayerGui.Notification.Event:Fire("New level!")
10    
11    end)
12    end

Output

13:00:19.592 - ServerScriptService.LevelNotifications:4: attempt to index global 'plr' (a nil value)

13:00:19.592 - Stack Begin

13:00:19.593 - Script 'ServerScriptService.LevelNotifications', Line 4

13:00:19.593 - Stack End

How to fix it? (I'm n00b at scripts xd)

1 comment

0

try "game:GetService("Players")" instead.

1 answer

✓ Accepted answer

Hence the name, the LocalPlayer is only available in local scripts. It contains a reference to the local player, or client, hence why it only works in local scripts. There's only 1 server per game that contains all the players in the game, which is why LocalPlayer is nil on the server. You'll have to use different means to get the player you want.

2 comments

0

Thanks for answer!

0

I accepted the answer for you thunder maker. @mishamol do get into the habit of accepting the solutions.

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