Attempt to get length of a Instance value

Hi fellow developers I having a issue with a line of code for my game


The Output is saying that “ServerScriptService.MainScript:38: attempt to get length of a Instance value”

I tried to rewrite the code but then it got messy so I went back to this .I’ve also tried looking at similar issues but nothings helping. If anyone could help that would be great thanks

1 Like

Try this:

local Children = GunSpawnpoints:GetChildren()
local ChosenGunSpawn = Children[math.random(1, #Children)]

You are trying to get the length of a model/folder which is not possible, you’ll need to do :GetChildren() (which returns a table) for the code to work ^^

It worked! thankyou so much for your help

1 Like