I've got this simple child-picker in one ModuleScript:
function pick(model)
local children = model:GetChildren()
local number = math.random(1,#children)
local child = children[number]
end
return pick
I'm not sure how to get this to return the child that's chosen, for other scripts to use. For example, I've got another Module Script which makes use of this:
local pick = require(game.Workspace.Pick)
function play(obj)
pick(game.Lighting.Sounds)
if pick.Name == obj.Name then
local file = pick:Clone()
file.Parent = obj
file.Pitch = 0.3 + math.random()
file:Play()
else
pick(game.Lighting.Sounds)
end
end
return play
I thought returning pick would also contain the child, but I guess not. Any help?

1 comment
Just add a 'return' inside your ModuleScript's returned function.