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

Image is not a valid member of Frame?

Asked by 5 years ago
Edited 5 years ago

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.

1 answer

Log in to vote
1
Answered by 5 years ago
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

0
Okay, thanks for the help! Unfortunately, when I run this script, I get an error saying: 22:26:06.910 - Players.BigChildren.PlayerGui.Cases.Frame.Common.LocalScript:26: attempt to index local 'result' (a number value). I have gotten this error for lines 26 and 23. I have tested the script only twice so I think it would say this for all the other lines that have to do with making a image visible. BigChildren 77 — 5y
0
can you provide a picture of how it looks like in your explorer, would make this easier Gameplayer365247v2 1055 — 5y
0
do you have a discord I could send this to? BigChildren 77 — 5y
Ad

Answer this question