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

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

Asked by 5 years ago

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)

0
try "game:GetService("Players")" instead. MArzalAlBuchariZ 33 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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.

0
Thanks for answer! mishamol 0 — 5y
0
I accepted the answer for you thunder maker. @mishamol do get into the habit of accepting the solutions. User#24403 69 — 5y
Ad

Answer this question