Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

math.random error? Help?

Asked by 10 years ago

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
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 GoldenPhysics 474 — 10y

1 answer

Log in to vote
1
Answered by
Xduel 211 Moderation Voter
10 years ago

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

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. MessorAdmin 598 — 10y
Ad

Answer this question