Attempt to get length of a Instance value

probably a real simple fix and im just forgetting something

Code:

local chosenCharacter = inGame[math.random(1, #inGame)]

Error:

ServerScriptService.Main:35: attempt to get length of a Instance value - Main:35
  Stack Begin
  Script 'ServerScriptService.Main', Line 35 - function executeEvent - Main:35
  Script 'ServerScriptService.Main', Line 116 - Main:116
  Stack End

what is inGame supposed to represent?

It’s a folder with all the in-game player’s characters

use ingame:GetChildren()

otherwise youre just specifiying the folder

Basic Example:

local myFolder = workspace.Folder:GetChildren() -- Folder containing parts

print(math.random(1, #myFolder))
1 is not a valid member of Folder "Workspace.Ingame" - Main:35
  Stack Begin
  Script 'ServerScriptService.Main', Line 35 - function executeEvent - Main:35
  Script 'ServerScriptService.Main', Line 116 - Main:116
  Stack End

Use :GetChildren() to index every child inside inGame.

Code:

local chosenCharacter = inGame:GetChildren()[RNG:NextInteger(1, #inGame:GetChildren())]

I’m using RNG because it was in another post of yours.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.