Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

math.random error? Help?

My ERROR :

**10:44:33.848 - Workspace.Map:51: attempt to get length of local 'v' (a userdata value) 10:44:33.849 - Stack Begin 10:44:33.852 - Script 'Workspace.Map', Line 51 - global Map 10:44:33.854 - Script 'Workspace.Map', Line 65 10:44:33.855 - Stack End*

local work=game:FindService('Workspace'):GetChildren()
local maps=game:FindService('Lighting'):GetChildren()
local hint=Instance.new('Message')
local Enabled=true

function nm(ID)
for _,v in pairs(work) do
if v.ClassName=='Sound' then
v:Pause() wait() 
v.SoundId='rbxassetid://'..ID wait()
v:Play()
end
end
end

function ls(plr)
for _,v in pairs(script:GetChildren()) do
if v.ClassName=='LocalScript' or v.ClassName=='Script' then
v:Clone().Parent=(game.Players[plr.Name]['Backpack'])
end
end
end

function Teleport(tp)
for _,v in pairs(game.Players:GetPlayers()) do 
ls(v)
wait(3)
v.Character:MoveTo(Vector3.new(tp))
end
end

function Map()
Enabled=false
nm(143736517)
hint.Parent=workspace hint.Text='Game Starting Soon...' 
wait(3) 
hint.Parent=game.Lighting
for _,mv in pairs(game:FindService('Lighting'):GetChildren()) do
local lastgame=''
if mv.ClassName=='Model' then
lastgame=mv.Name
for _,mm in pairs(mv:GetChildren()) do
if mm.ClassName=='NumberValue' then
nm(mm.Value)
end
end
mv:Clone().Parent=game.Workspace
for _,vmm in pairs(mv:GetChildren()) do
if vmm.ClassName=='Model' and vmm.Name=='Spawns' then
for _,v in pairs(vmm:GetChildren()) do
local a=math.random(1,#v)  --- This is the error line here :/ Help please?
Teleport(a.Position)
end
end
end
wait(60)
mv:remove()
Enabled=true
end
end
end

1 comment

0

By the way, your code could be reviewed faster, therefore getting you help faster if you learn to indent code to make it easier for humans to read. http://wiki.roblox.com/index.php?title=Writing_Clean_Code

1 answer

"v"is not a number, so therefore "#v" does not work. I beleive you mean't "#v:GetChildren()".

1 comment

0

Well I have a model full of part and I need the script to randomly get a part then teleport the player to the part. But the script got the Spawn model and the part.

This discussion is preserved as it was. New answers, comments, and votes are closed.