I defined the variables in the error code in a module script in ServerScriptService. The module script goes:


local teamModule = {}

local DataStore2 = require(1936396537)

DataStore2.Combine("MainKey","Team") -- You Can Change MainKey To Any New Value To Reset The DataBase

local defaultTeam = "White"

function teamModule:SetPlayerTeam(player)
	if player:IsA("Player") then
	
   	        local excessData = Instance.new("Folder",player)
		excessData.Name = "ExcessData"
		
		local teamValue = Instance.new("StringValue",excessData)
		teamValue.Name = "Team"
		
		local teamStore = DataStore2("Team",player)
		
		local function updateTeam(team)
			player.ExcessData.Team.Value = team
		end
		
		updateTeam(teamStore:Get(defaultTeam))
		
		teamStore:OnUpdate(updateTeam)
	else
		error("The First Parameter Has To Be A Player")
	end
end

return teamModule


However, in the script, there is this line of code:

local team = game:GetService("Teams"):FindFirstChild(player.ExcessData.Team.Value).TeamColor

and when i play the game in studio, it says attempt to index nil with team color. How can i fix this?