In my minigames, everything goes well... the choosing random minigame, the teleporting, but when a few plates disappear, this comes out in the output:
06:33:40.238 - Transparency is not a valid member of Model 06:33:40.238 - Script 'Workspace.DisappearingPlates.removePlates', Line 25 - local disappearingPlates 06:33:40.239 - Script 'Workspace.DisappearingPlates.removePlates', Line 33 06:33:40.239 - Stack End
-- The function while wait(1) do local function disappearingPlates() local plates = script.Parent:GetChildren() local ranNum1 = plates[math.random(1, #plates)] -- problem :( local ranNum2 = plates[math.random(1, #plates)] --while ranNum1 == ranNum2 do --wait() --ranNum2 = plates[math.random(1, #plates)] --end for i = 0, 1, 0.05 do wait() ranNum1.Transparency = i ranNum2.Transparency = i end ranNum1:Destroy() ranNum2:Destroy() end disappearingPlates() -- problem :( end -- end of script :D
Your problem is that either ranNum1
or ranNum2
is returning a model. And since you index the Transparency
property on line 19 and 20 then it is going to error if either variable is a model due to the fact the models don't have the Transparency property - hence your error Transparency is not a valid member of Model
.
--[[You should really consider putting your function on the outside of the while loop, otherwise you're re-defining the function every time the loop iterates.]] function disappearingPlates() local children,plates = script.Parent:GetChildren(),{} --Create a table filled only with parts. for _,v in next,children do if v:IsA("BasePart") then table.insert(plates,v) end end --Select randomely from created table local ranNum1 = plates[math.random(1, #plates)] local ranNum2 = plates[math.random(1, #plates)] --Change ranNum2's value as long as it is equal to ranNum1 while ranNum1 == ranNum2 and wait() do ranNum2 = plates[math.random(1, #plates)] end for i = 0, 1, 0.05 do wait() ranNum1.Transparency = i ranNum2.Transparency = i end ranNum1:Destroy() ranNum2:Destroy() end while wait(1) do disappearingPlates() end