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

Local player a nil value?

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

1

It is in a local script, right?

1

Like @NowUndoThatMistake said, it should in LocalScript. Because, Players.LocalPlayer only work for LocalScript.

0

Thank you, I did not know that.

1 answer

✓ Accepted answer

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)

2 comments

0

Thank you for helping :)

0

np

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