|
| 27 Oct 2014 03:52 AM |
I just keep getting this error "19:50:38.559 - Workspace.GameManager:793: attempt to index global 'a' (a nil value)"
function _G.changeMap(map) print(map.Name .. " is being loaded.") local totalSpace = 0 local list = game.Workspace.Map:getChildren() for x=1, #list do list[x]:remove() end a = game.Lighting.Maps[map]:Clone() a.Parent = game.Workspace a.Name = "Map" end for _, v in pairs (a:GetChildren()) do if a.className == "Part" and a.TopSurface == "Studs" then totalSpace = totalSpace + 1 end local nameData = _G.explode("|", a.Data.Value)
if _G.skyBox then _G.changeSky(nameData[2]) end
script.maxUsage.Value = totalSpace * (percentAvailable / 100) script.mapName.Value = a.Name return _G.decompressed end |
|
|
| Report Abuse |
|
|
| |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 27 Oct 2014 04:42 AM |
| game.Lighting.Maps[map]:Clone() either returns nil or you need to set it to local |
|
|
| Report Abuse |
|
|
| |
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
|
| 28 Oct 2014 08:22 AM |
Unless you have already defined a, then you need to put local by it. I.E,
local a = game.Lighting.Maps[map]:Clone()
|
|
|
| Report Abuse |
|
|
|
| 28 Oct 2014 08:25 AM |
Changed it and the map spawned, but it still didnt do the for_,v in pairs partt
function _G.changeMap(map) print(map.Name .. " is being loaded.") local totalSpace = 0 local list = game.Workspace.Map:getChildren() for x=1, #list do list[x]:remove()
end local a = map:Clone() a.Parent = game.Workspace a.Name = "Map" for _, v in pairs (a:GetChildren()) do if a.className == "Part" and a.TopSurface == "Studs" then totalSpace = totalSpace + 1 end end local nameData = _G.explode("|", a.Data.Value)
if _G.skyBox then _G.changeSky(nameData[2]) end
script.maxUsage.Value = totalSpace * (percentAvailable / 100) script.mapName.Value = a.Name return _G.decompressed end
|
|
|
| Report Abuse |
|
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
|
| 28 Oct 2014 08:30 AM |
| change a.className to a:IsA("Part"). This is usually preferred. Does the console give you any errors? |
|
|
| Report Abuse |
|
|
|
| 28 Oct 2014 08:33 AM |
No errors, it's just not increasing the value.
|
|
|
| Report Abuse |
|
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
|
| 28 Oct 2014 08:39 AM |
--goes after a-- local ac = a:GetChildren()
for i=1, #ac do if ac[i]:IsA("Part") and ac[i].TopSurface == "Studs" then totalSpace = totalSpace + 1 end end
Should work. I have not tested it though. |
|
|
| Report Abuse |
|
|
| |
|
|
| 28 Oct 2014 09:00 AM |
current script, only problem is totalspace isn't changing
function _G.changeMap(map) print(map.Name .. " is being loaded.") local totalSpace = 0 local list = game.Workspace.Map:getChildren() for x=1, #list do list[x]:remove() end local a = map:Clone() a.Parent = game.Workspace a.Name = "Map" local ac = a:GetChildren() for i=1, #ac do if ac[i]:IsA("Part") and ac[i].TopSurface == "Studs" then totalSpace = totalSpace + 1 end end --local nameData = _G.explode("|", a.Data.Value)
--if _G.skyBox then --_G.changeSky(nameData[2]) --end
script.maxUsage.Value = totalSpace * (10 / 100) script.mapName.Value = map.Name return _G.decompressed end
|
|
|
| Report Abuse |
|
|
|
| 28 Oct 2014 09:03 AM |
ac[i].TopSurface == "Studs" This doesn't work, as far as I know, that only works to set it.
use
ac[i].TopSurface == Enum.SurfaceType.Studs |
|
|
| Report Abuse |
|
|
|
| 28 Oct 2014 09:05 AM |
You legend!
it's working, thank you everyone! |
|
|
| Report Abuse |
|
|
|
| 28 Oct 2014 11:23 AM |
I've changed one part, after it's spawned I want it to, remove every model called Forest and replace it with one called Forest from lighting, and the same thing but with Gold. No output, please help.
function _G.changeMap(map) print(map.Name .. " is being loaded.") local totalSpace = 0 local list = game.Workspace.Map:getChildren() for x=1, #list do list[x]:remove() end local a = map:Clone() a.Parent = game.Workspace a:MoveTo (Vector3.new(191.6, 8, 360)) a.Name = "Map"
local ac = a:GetChildren() for i=1, #ac do if ac[i]:IsA("Part") and ac[i].TopSurface == Enum.SurfaceType.Studs then totalSpace = totalSpace + 1 end end local ac = game.Workspace.Map:GetChildren() for i=1, #ac do if ac[i]:IsA("Part") and ac.Forest ~= nil then ac.Forest:Destroy() local res = game.Lighting.Database.NaturalResources.Forest:clone() res.Parent = ac res:MoveTo(ac.Position + Vector3.new(3, 0, 3)) end end local ac = game.Workspace.Map:GetChildren() for i=1, #ac do if ac[i]:IsA("Part") and ac.Gold ~= nil then ac.Gold:Destroy() local res = game.Lighting.Database.Gold:clone() res.Parent = ac res:MoveTo(ac.Position) end end
local nameData = _G.explode("|", a.Data.Value)
if _G.skyBox then _G.changeSky(nameData[2]) end
script.maxUsage.Value = totalSpace * (10 / 100) script.mapName.Value = map.Name return _G.decompressed end
|
|
|
| Report Abuse |
|
|
|
| 28 Oct 2014 11:36 AM |
this is the part I need help with, please help.
local ac = game.Workspace.Map:GetChildren() for i=1, #ac do if ac[i]:IsA("Part") and ac.Forest ~= nil then ac.Forest:Destroy() local res = game.Lighting.Database.NaturalResources.Forest:clone() res.Parent = ac res:MoveTo(ac.Position + Vector3.new(3, 0, 3)) end end local ac = game.Workspace.Map:GetChildren() for i=1, #ac do if ac[i]:IsA("Part") and ac.Gold ~= nil then ac.Gold:Destroy() local res = game.Lighting.Database.Gold:clone() res.Parent = ac res:MoveTo(ac.Position) end end |
|
|
| Report Abuse |
|
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
|
| 28 Oct 2014 11:44 AM |
local ac = game.Workspace.Map:GetChildren() for i=1, #ac do if ac[i]:IsA("Part") and ac.Forest ~= nil then ac.Forest:Destroy() local res = game.Lighting.Database.NaturalResources.Forest:clone()--Replace lighting with serverStorage, and move everything into there. Usually better. res.Parent = ac --< [[this is your problem. GetChildren() returns a read only table. try res.Parent = game.Workspace.Map]]-- res:MoveTo(ac.Position + Vector3.new(3, 0, 3)) end end local ac = game.Workspace.Map:GetChildren() for i=1, #ac do if ac[i]:IsA("Part") and ac.Gold ~= nil then ac.Gold:Destroy() local res = game.Lighting.Database.Gold:clone() res.Parent = ac --< Do the same thing you did for forest here res:MoveTo(ac.Position) end end
|
|
|
| Report Abuse |
|
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
|
| 28 Oct 2014 11:45 AM |
| If that doesn't work, change ac.Forest ~= nil to ac[I].Name == Forest. Same thing for gold. |
|
|
| Report Abuse |
|
|
|
| 28 Oct 2014 11:52 AM |
| Gold and Forest are models in the parts |
|
|
| Report Abuse |
|
|
|
| 28 Oct 2014 11:56 AM |
| nevermind all I have got it working :D |
|
|
| Report Abuse |
|
|