Attempt to index nil with 'Team'

Hey everyone.

I’ve done some messing around and I am still not able to find out what’s causing this error.
Any help would be appreciated.

This code right here keeps coming back to this error code: Workspace.Game.Scripts.Main:89: attempt to index nil with ‘Team’

function regionVisualEffect()
	if Player.Team == RedTeam then
		regionVisual.Transparency = 0
		regionVisual.Color = Color3.fromRGB(0,0,255)
		tween:Create(regionVisual,TweenInfo.new(1),{Transparency = .9}):Play()
1 Like

it means you didnt define the variable “Player” in line 2

1 Like

I probably should have included this, but figured I didn’t need it. I did define Player above it.

The actual full code:

local Player = game:GetService("Players").LocalPlayer
local RedTeam = game:GetService("Teams")["Red Team"]

function regionVisualEffect()
	if Player.Team == RedTeam then
		regionVisual.Transparency = 0
		regionVisual.Color = Color3.fromRGB(0,0,255)
		tween:Create(regionVisual,TweenInfo.new(1),{Transparency = .9}):Play()
1 Like

then it is because you put it in a regular Script, where there is no such thing as LocalPlayer. LocalPlayer only exists when written in a LocalScript

2 Likes

I see, thanks for the help. How would I go about fixing this without having to put it into a localscript?

1 Like
game:GetService("Players").PlayerAdded:Connect(function(Player)
if Player.Team == RedTeam then
		regionVisual.Transparency = 0
		regionVisual.Color = Color3.fromRGB(0,0,255)
		tween:Create(regionVisual,TweenInfo.new(1),{Transparency = .9}):Play()
end
end)
5 Likes