0
I have a game in Roblox for which I create a series of platforms like so:
local function makePlat(pX,pY,pZ, colNum, rowNum, eliminated, number)
local Platform = {}
Platform.Part = Instance.new("Part", workspace)
Platform.Part.Position = Vector3.new(pX,pY,pZ)
Platform.Part.Size = Vector3.new(10,1,10)
Platform.Part.BackSurface = "Smooth"
Platform.Part.FrontSurface = "Smooth"
Platform.Part.BottomSurface = "Smooth"
Platform.Part.TopSurface = "Smooth"
Platform.Part.LeftSurface = "Smooth"
Platform.Part.RightSurface = "Smooth"
Platform.Part.Material = "Glass"
Platform.Part.BrickColor = BrickColor.new("Black")
Platform.Part.Transparency = 0
Platform.Part.Anchored = true
Platform.Column = colNum
Platform.Row = rowNum
Platform.Eliminated = false
Platform.Number = number
return Platform
end
local allPlats = {}
local allParts = {}
local a = 1
for i = 1, 12 do
for j = 1, 12 do
maPlat = makePlat(i*16,0,j*16, i, j, false, a)
table.insert(allPlats, maPlat)
table.insert(allParts, maPlat.Part)
a = a + 1
end
end
Then, later on in the script, I have a function that grabs a series of those platforms and performs some changes on them, like so:
local function ripple(v, teamColorReady, col, row)
local part1 = allParts[v.Number + 1]
local part2 = allParts[v.Number + 2]
local part3 = allParts[v.Number + 3]
--sideGreen
local part4 = allParts[v.Number - 1]
local part5 = allParts[v.Number - 2]
local part6 = allParts[v.Number - 3]
--sideRed
local part7 = allParts[v.Number + 12]
local part8 = allParts[v.Number + 24]
local part9 = allParts[v.Number + 36]
--sideBlue
local part10 = allParts[v.Number - 12]
local part11 = allParts[v.Number - 24]
local part12 = allParts[v.Number - 36]
local lapse = .1
local high = 6
local medium = 3
local fadeNone = 0
local fadeLow = .75
local fadeMed = .5
local fadeHigh = 0
for i = 1, 7 do
if i == 1 then
--sideYellow
part1.Size = Vector3.new(10,high,10)
part1.Transparency = fadeHigh
part1.BrickColor = BrickColor.new(teamColorReady)
part1.Material = "Neon"
--sideGreen
part4.Size = Vector3.new(10,high,10)
part4.BrickColor = BrickColor.new(teamColorReady)
part4.Material = "Neon"
--sideRed
part7.Size = Vector3.new(10,high,10)
part7.BrickColor = BrickColor.new(teamColorReady)
part7.Material = "Neon"
--sideBlue
part10.Size = Vector3.new(10,high,10)
part10.BrickColor = BrickColor.new(teamColorReady)
part10.Material = "Neon"
wait(lapse)
elseif i == 2 then
--sideYellow
part1.Size = Vector3.new(10,medium,10)
part1.Transparency = fadeMed
part2.Size = Vector3.new(10,medium,10)
part2.Transparency = fadeMed
part2.BrickColor = BrickColor.new(teamColorReady)
part2.Material = "Neon"
--sideGreen
part4.Size = Vector3.new(10,medium,10)
part5.Size = Vector3.new(10,medium,10)
part5.BrickColor = BrickColor.new(teamColorReady)
part5.Material = "Neon"
--sideRed
part7.Size = Vector3.new(10,medium,10)
part8.Size = Vector3.new(10,medium,10)
part8.BrickColor = BrickColor.new(teamColorReady)
part8.Material = "Neon"
--sideBlue
part10.Size = Vector3.new(10,medium,10)
part11.Size = Vector3.new(10,medium,10)
part11.BrickColor = BrickColor.new(teamColorReady)
part11.Material = "Neon"
wait(lapse)
etc... This is to create a ripple effect on the platforms. The problem I have is that, depending on where the player is standing (i.e, next to the edge of the whole square of platforms) the variables of part1, part2, etc... might not exist. So I need a way of testing the the platform exists before performing any change on them else I get an error.
I know that Roblox allows to check if something exists by using
WaitForChild()
and you can use this in the tree hierarchy of game.workspace etc... but you can't use this to check if an element in an array (table in lua) exists.
So how can I check that a variable (such as part1, part2, etc...) inside a table is pointing towards an actual object in the game?
Thanks
