Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Osamiku 12
4 years ago

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

Log in to vote
0
Answered by
blowup999 659 Moderation Voter
4 years ago
Edited 4 years ago

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

Ad

Answer this question