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:
local plr = game:GetService("Players").LocalPlayer
local Character = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local vr = game.StarterGui.ScreenGui.Frame.RedPlayer.RedPlayerScore.RedValue
local vb = game.StarterGui.ScreenGui.Frame.BluePlayer.BluePlayerScore.BlueValue
Humanoid.Died:Connect(function()
if plr.TeamColor == BrickColor.new("Bright blue") then
vr = vr + 1
else
vb = vb + 1
end
end)
Second one:
local plr = game.Players.LocalPlayer
local f = game.StarterGui.ScreenGui.Frame
local rn = f.RedPlayer.RedPlayerName
local bn = f.BluePlayer.BluePlayerName
if plr.TeamColor == BrickColor.new("Bright blue") then
bn.Text = plr.Name
else
rn.Text = plr.Name
end
Thank you for trying to help. I appreciate it very much.

3 comments
It is in a local script, right?
Like @NowUndoThatMistake said, it should in LocalScript. Because, Players.LocalPlayer only work for LocalScript.
Thank you, I did not know that.