Hello fellow developers!
I am a novice developer, although I have created several games last 6 months.
Now I am developing an obby game and there are 24 checkpoints.
I am writing a server script in ServerScriptService so that a player can get some reward once per game session when a player touch a checkpoint part.
For that, I am using CollectionService and set tags for the checkpoints. These tag names are “CP1”, “CP2”,…“CP24”.
Once a player touch a checkpoint, the player should be tagged with the checkpoint tag name.
The following is part of code and I got an error message about line 17.
“attempt to index nil with ‘Connect’”.
That should result into the error “Attempt to index table with Connect.” However, it returns “Attempts to index nil with Connect”. You are however correct about CollectionService returning arrays. I believe the instances are tagged after this script runs, so nil is returned everytime.
When op inserts the tagged parts array into the taggedParts table this creates a table nestled in a table.
taggedParts = {
{arrray of parts tagged with CP1}, {arrray of parts tagged with CP2},
}
with all the arrays up to 24.
When op loops through the taggedParts table on line 15, the taggedPart variable is a table. This is the array of all the tagged parts with the tag. To get the actually parts, OP would then need to loop through the table from taggedParts, thus the for loop in the for loop. OP can then connect their touched event on line 17 to the part defined in the for loop.
Just to make it clear in simple language. When you use :GetTagged() it adds a table inside the table. So you need to loop inside of the second table. Hopefully you get what I mean!
It’s not exactly what it does, but I just explained in a simple language
Sorry but I am a novice developer and I didn’t know how to do that.
I checked the API-reference (Collection Service) and
thought I can use only one instance for the argument of GetTagged().
Because 24 tag names are all different, so I didn’t know how to handle it other than using a table. I will appreciate if u let me know any simpler ways.