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

Local player a nil value?

Asked by
DesertusX 435 Moderation Voter
5 years ago
Edited 5 years ago

I made two scripts and they both don't work.In the output it says for both of them: "attempt to index 'plr' (a nil value)". Could anyone please help point out the problem. Here are both of the scripts:

01local plr = game:GetService("Players").LocalPlayer
02local Character = plr.Character or plr.CharacterAdded:Wait()
03local Humanoid = Character:WaitForChild("Humanoid")
04local vr = game.StarterGui.ScreenGui.Frame.RedPlayer.RedPlayerScore.RedValue
05local vb = game.StarterGui.ScreenGui.Frame.BluePlayer.BluePlayerScore.BlueValue
06 
07Humanoid.Died:Connect(function()
08   if plr.TeamColor == BrickColor.new("Bright blue") then
09    vr = vr + 1
10    else
11        vb = vb + 1
12 
13end
14 
15end)

Second one:

01local plr = game.Players.LocalPlayer
02local f = game.StarterGui.ScreenGui.Frame
03local rn = f.RedPlayer.RedPlayerName
04local bn = f.BluePlayer.BluePlayerName
05 
06if plr.TeamColor == BrickColor.new("Bright blue") then
07    bn.Text = plr.Name
08else
09        rn.Text = plr.Name
10end

Thank you for trying to help. I appreciate it very much.

1
It is in a local script, right? xAtom_ik 574 — 5y
1
Like @NowUndoThatMistake said, it should in LocalScript. Because, Players.LocalPlayer only work for LocalScript. Block_manvn 395 — 5y
0
Thank you, I did not know that. DesertusX 435 — 5y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
5 years ago
01local Character = plr.Character or plr.CharacterAdded:Wait()
02local Humanoid = Character:WaitForChild("Humanoid")
03local vr = game.StarterGui.ScreenGui.Frame.RedPlayer.RedPlayerScore.RedValue
04local vb = game.StarterGui.ScreenGui.Frame.BluePlayer.BluePlayerScore.BlueValue
05plr.TeamColor = BrickColor.new ( "Bright blue")
06Humanoid.Died:Connect(function()
07   if plr.TeamColor == BrickColor.new (" Bright blue") then
08    vr = vr + 1
09    else
10        vb = vb + 1
11 
12end
13 
14end)
0
Thank you for helping :) DesertusX 435 — 5y
0
np JesseSong 3916 — 5y
Ad

Answer this question