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

A error on "frame doesn't belong to screen Gui" How to fix?

Asked by 7 years ago

This is my script: local button = script.Parent local name = script.Parent:WaitForChild("ElementName") local message = script.Parent.Parent.Parent.ChoiceFrame:WaitForChild("ConfirmationMessage") local frame = script.Parent.Parent.Parent:WaitForChild("OptionFrame") local sound = script.Parent:WaitForChild("Splash") local fire = script.Parent.Parent:WaitForChild("FlameReaper") local water = script.Parent.Parent:WaitForChild("Aqua") local earth = script.Parent.Parent:WaitForChild("EarthGuardian")

button.MouseButton1Down:connect(function() if frame.Visible == false then frame.Visible = true message.Text = "Are you sure you want to choose "..name.Value..", a Water type Element as your starter Element? Answer with ('Yes' or 'No')" if earth.Visible == true then earth.Visible = false if water.Visible == true then water.Visible = false if fire.Visible == true then fire.Visible = false end end end end end)

button.MouseEnter:connect(function() wait(0.2) sound:Play() sound.Volume = 0.5 wait(1) end)

button.MouseLeave:connect(function() wait(0.2) sound.Volume = 0 sound:Play() wait(1) end)

This is the error, help me fix it please I tried so many times no matter what I do it won't work ChoiceFrame is not a valid member of ScreenGui

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

To start, I recommend that, when posting your code, click on that "Lua Icon", above the area where you write your post, and put the code inside the set of "~" that just appeared, so it's easier to read your code.

About your error, what could've happened is that, you haven't waited until ChoiceFrame has loaded.

local choiceFrame = script.Parent.Parent.Parent:WaitForChild("ChoiceFrame")
local message = choiceFrame:WaitForChild("ConfirmationMessage") 

Small tip: I've noticed that your checking if the frames are visible, and if they are, set them to invisible:

if earth.Visible == true then 
    earth.Visible = false 
    if water.Visible == true then 
        water.Visible = false 
        if fire.Visible == true then 
            fire.Visible = false 
        end 
    end 
end

You really don't need to check if they're visible.

If they are visible, and set it to invisible, they will become invisible.

If they are invisible, and set it to invisible, then they will continue invisible.

This is just a small tip so you consume less time writing your code, and in the end, make a more efficient and clean code.

local button = script.Parent 
local name = script.Parent:WaitForChild("ElementName") 
local choiceFrame = script.Parent.Parent.Parent:WaitForChild("ChoiceFrame")
local message = choiceFrame:WaitForChild("ConfirmationMessage")  
local frame = script.Parent.Parent.Parent:WaitForChild("OptionFrame") 
local sound = script.Parent:WaitForChild("Splash") 
local fire = script.Parent.Parent:WaitForChild("FlameReaper") 
local water = script.Parent.Parent:WaitForChild("Aqua") 
local earth = script.Parent.Parent:WaitForChild("EarthGuardian")

button.MouseButton1Down:connect(function() 
    if frame.Visible == false then
        --Set frame to visible
        frame.Visible = true 

        --Show players the message
        message.Text = "Are you sure you want to choose "..name.Value..", a Water type Element as your starter Element? Answer with ('Yes' or 'No')" 

        --Hide the player's element Guis
        earth.Visible = false 
        water.Visible = false 
        fire.Visible = false 
    end 
end)

button.MouseEnter:connect(function() 
    wait(0.2) 
    sound:Play() 
    sound.Volume = 0.5 
    wait(1) 
end)

button.MouseLeave:connect(function() 
    wait(0.2) 
    sound.Volume = 0 
    sound:Play() 
    wait(1) 
end)
0
I will try this out thanks for trying to help BlackOrange3343 2676 — 7y
0
This helped, This worked You awesome answer accepted BlackOrange3343 2676 — 7y
Ad
Log in to vote
0
Answered by
KenUSM 53
7 years ago

Simple there is either nothing in your ScreenGUI named "frame" if there is something named "Frame" capitalize the F in your script. to lowercase it in your Game.StarterGUI.ScreenGUI and you should see Frame if not then insert it.

0
I have a frame it's called Option frame and it was in the gui the problem is it won't find it BlackOrange3343 2676 — 7y

Answer this question