Okay, I am working on a little project so I can learn more about lua, I have no hopes into turning this project into a game but what I am working on is a case system and my goal is here trying to make a random image show up in the frame where I put the images. Here is my code:
script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Visible = false script.Parent.Parent.Parent.Parent.YouGot.BigFrame.Visible = true script.Parent.Parent.Parent.Parent.YouGot.BigFrame.Result:GetChildren().Visible = false end) while true do result = math.random(1,5) if result == 1 then game.StarterGui.YouGot.BigFrame.Result.BrilliantBombtastic.Visible = true end if result == 2 then game.StarterGui.YouGot.BigFrame.Result.Prankster.Visible = true end if result == 3 then game.StarterGui.YouGot.BigFrame.Result.GravityCoil.Visible = true end if result == 4 then game.StarterGui.YouGot.BigFrame.Result.GreenShutterShades.Visible = true end if result == 5 then game.StarterGui.YouGot.BigFrame.Result.NinjaMaskOfLight.Visible = true end end
When I run the game everything works fine but the error I get right off the bat is that none of the images are valid members of Frame. The "Frame" the output is directing to is the "Result" which is the frame where all the images are(this is only a guess, I could be wrong but this guess makes sense since all my frames have different names). Any help is appreciated! Thanks guys. EDIT: I am using a Local Script.
script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Visible = false script.Parent.Parent.Parent.Parent.YouGot.BigFrame.Visible = true script.Parent.Parent.Parent.Parent.YouGot.BigFrame.Result:GetChildren().Visible = false end) local Result for i,result in pairs(game.Players.LocalPlayer.PlayerGui.YouGot.BigFrame.Result:GetChildren()) do Result = result end while true do wait(1) local result = math.random(1,5) if result == 1 then result.BrilliantBombtastic.Visible = true end if result == 2 then result.Prankster.Visible = true end if result == 3 then result.GravityCoil.Visible = true end if result == 4 then result.GreenShutterShades.Visible = true end if result == 5 then result.NinjaMaskOfLight.Visible = true end end
startergui is the gui that replicates to all the players and should not be changed so instead there is something called playergui which is the gui that is local to all the players and only the local player can click things in their player gui, so here we access the playergui's children and say that result is all the children of BigFrame.Result, and in the loop we change their visibility to true if the math.random result says so. also in a while true do loop ALWAYS use a wait otherwise your studio WILL crash since the loop is trying to go infinite speed and that is not possible so i added a wait with 1 second waiting time