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

Attempt to index a nil value?

Asked by 5 years ago
Edited 5 years ago

I'm not sure why this is happening.

Basically, I'm trying to send a table through a remote event which tells the client what players are in the game. From this, I want to fill up a text box full of the names of the players.

playersRemote = game.ReplicatedStorage.playersExchange


playersRemote.OnClientEvent:connect(function(arg)

    players = arg
    for i=1,#players do
        if players[i].Name == game.Players.LocalPlayer then
            table.remove(players,i)
        end
    end
    --Using the above code to take out the local player from the table

    for i=1, #players do

            script.Parent:FindFirstChild("plr"..i.."name").Text = players[i].Name
            --This is where it says I'm trying to index a nil value
    end
    script.Parent.Visible = true
end)
0
oh my deprecated cde green271 635 — 5y
0
Thank you for pointing that out, but that doesn't help anyone. What part of my code is deprecated? I'm just trying to learn remote events and filtering enabled gameplay since I left roblox about a year ago. MezornoIV 25 — 5y
0
connect is deprecated in favor of Connect & you should be using local variables green271 635 — 5y
0
if players[i].Name == game.Players.LocalPlayer --> game.Players.LocalPlayer.Name, as for the nil part..you have a bunch of children of script.Parent named "plr1name", "plr2name", etc? Because that is what your script is currently doing but it doesn't quite match up with the question description Vulkarin 581 — 5y
View all comments (7 more)
0
Thank you, and yes that's how my gui is laid out. MezornoIV 25 — 5y
0
Okay, is the nil value players[i].Name or the FindFirstChild line? Vulkarin 581 — 5y
0
It's on the find first child line MezornoIV 25 — 5y
0
There are equal amounts of "plr<num>name" as there are players? Maybe it will help if you look yourself in explorer to make sure they all exist Vulkarin 581 — 5y
0
There can never be more than 4 players in my game, and because 1 of the players is the local player (and wont need to see themselves in the list), I've only put 3, so they are all there. MezornoIV 25 — 5y
0
Or possibly you would require a WaitForChild in the event that they are being created while the loop is running Vulkarin 581 — 5y
0
The error means either "script.Parent:FindFirstChild("plr"..i.."name")" doesn't exist or "players[i]" doesn't exist. Find out which one. I'm guessing the former. gullet 471 — 5y

Answer this question