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

attempt to index nil with "match" ??? script error

I am typing a script that will detect whether or not an items Name matches what the script says, but I repeatedly get this error in the output:

Players.Osamiku.PlayerGui.Client:37: attempt to index nil with 'match'

here is the script, it happens on line 37:

--Player--
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local gui = player:WaitForChild("PlayerGui")
local ui= gui:WaitForChild("ui")
 
--Assets--
local rep = game.ReplicatedStorage
local assets = rep.Assets

--Maps--
local maps = assets.Maps

--Signals--
local signals = assets.Signals
local event = signals.Event
local fevent = signals.FEvent

--Game Variables--
local Game = game.StarterGui.Game
local stats = Game.Stats
local ScreenGUI = Game.Special.VotingGUIs.ScreenGUI
local Part = ScreenGUI:GetChildren()

--Static Variables--
local vars = {
	currentVote=nil;
	services={};
}

--Primary Events--
event.OnClientEvent:connect(function(variables)
	if variables.reason == "startVoting" then
		table.insert(vars.services, game:GetService("RunService").RenderStepped:connect(function()
			local ray = Ray.new(char.PrimaryPart.CFrame.p, Vector3.new(0.-1000.0))
			local object = Part
			if object and object.Name:match("votingGUI")then
				local votingGUINum = tonumber(object.Name:match("%d+"))
				if vars.currentVote==nil then
					vars.currentVote = votingGUINum
					event:FireServer({reason="voteOnMap"; itemNum=votingGUINum;})
				elseif vars.currentVote~=votingGUINum then
					vars.currentVote = votingGUINum
					event:FireServer({reason="voteOnMap"; itemNum=votingGUINum;})
				end
			elseif vars.currentVote~=nil then
				vars.currentVote=nil
				event:FireServer({reason="removeFromVote"})
			end
		end))
	elseif variables.reason == "endVoting" then
		for a,b in pairs(vars.services) do
			b:disconnect()
		end
		vars.services={}
	end
end)

--Initiate Title Updater
game:GetService("RunService").RenderStepped:connect(function()
	ui:WaitForChild("Title").Text = game.StarterGui.Game.Stats.Status.Value
end)


if anyone knows how to solve this, please tell me. Thanks

1 answer

In the script above, "Part" is ScreenGui:GetChildren() You then take Part and do local object = Part and object.Name:match("votingGUI")

However, because Part is ScreenGui:GetChildren() it returns a table of object values.

To fix this, I would surround that statement with: for i,v in pairs(Parts) do local object = v end

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