I'm getting an error that says: Workspace.Camera.screenPiece.back.shop stuff.money.Script:3: attempt to index local 'player' (a nil value)

local char = script.Parent.Parent.Parent.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(char)
local resources = player.resources

while wait() do
	if player then
	script.Parent.Text = tostring(resources.Value)
	end
end