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
4 years ago
Edited 4 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:

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.

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

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago

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 plr.TeamColor = BrickColor.new ( "Bright blue") Humanoid.Died:Connect(function() if plr.TeamColor == BrickColor.new (" Bright blue") then vr = vr + 1 else vb = vb + 1 end end)
0
Thank you for helping :) DesertusX 435 — 4y
0
np JesseSong 3916 — 4y
Ad

Answer this question