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

Global Variables: attempt to index nil with 'Name'?

Hello!

First off, sorry for my messy script haha.

I'm getting the following error:

23:48:59.571 - Players.7z99.PlayerGui.ScreenGui2.Frame.TextLabel.TextLabel_Roundify_12px.TextLabel.LocalScript:39: attempt to index nil with 'Name'

and I'm not sure why.

Script where the global variable is declared and given a value:

function eliminatePlayer()
	
	local smallestValue = math.huge
	_G.smallestPlayer = nil
	
	
	local playingList = game.Teams.Playing:GetPlayers()

	local playerTable = {}

	for i, v in pairs(playingList) do
	
		table.insert(playerTable, playingList[i].Name) 
		print(playingList[i].Name)
		
	end



	for i, v in pairs(playerTable) do
	
		local currentPlayer = game.Players:FindFirstChild(v)
	
  		if currentPlayer.PlayerGui.ScreenGui.ProgressBar.Config.Progress.Value < smallestValue then
   			_G.smallestPlayer = currentPlayer
   			smallestValue = currentPlayer.PlayerGui.ScreenGui.ProgressBar.Config.Progress.Value
			print(smallestValue)
  		end

		print(_G.smallestPlayer)
		
	end
	
	for i,v in pairs(playerTable) do
		if v == _G.smallestPlayer then
			table.remove(playerTable, i)
		end
	end
	
	_G.smallestPlayer.Team = game.Teams.Lobby
	
	game.Players[_G.smallestPlayer.Name]:LoadCharacter()
	
	for i,v in pairs(game.Teams.Complete:GetPlayers()) do
		print(v)
		v.Team = game.Teams
		v:LoadCharacter()
	end
		
	FireClient()
			
	waitRoundOver()

end

Here's the script where I'm trying to access the global variable, but is outputting the error:

function plrrmv(player)
	local splayer = _G.smallestPlayer
	
	print("player remove") -- it is printed, so this is being executed.
	
	wait()
	local newpos = UDim2.new(0.5, 0, 0.5, 0)
	local oldpos = UDim2.new(0.5, 0, 2, 0)
	script.Parent.Parent:TweenPosition(newpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5) 
	wait(.1)
	local playerUsername = game.Players.LocalPlayer.Name

	--oblox services
	local ReplicatedStorage = game:GetService("ReplicatedStorage")

	--equire module
	local TypeWriter = require(ReplicatedStorage:WaitForChild("TypeWriter"))
	TypeWriter.typeWrite(script.Parent, "Round Over! "..splayer.Name.."was eliminated!")
	
	wait(2)
	
	script.Parent.Parent:TweenPosition(oldpos, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.5)
	
end

1 answer

I think on line 13 and 14 you should just replace playingList[i].Name with just v.

5 comments

0

That's not the problem though, it's with the global variables.

0

They are near the bottom of the first script.

0

On line 40, use TeamColor.

0

_G.smallestPlayer.TeamColor = BrickColor.new("Put the colour of the Lobby team here")

0

I’m not looking for feedback, I’m looking to make my scripts work.

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