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

Help on how to end functions?

Asked by
NotSoNorm 777 Moderation Voter
10 years ago

So I am trying to get it so if song1 is visible then song 2 is visible and if song 2 is visible then song three would be visible, I put an end. Would that fix it?

script.Parent.MouseButton1Down:connect(function()
    script.Parent.Parent.Parent.Parent.PlayerLocalSound:Stop()
    if script.Parent.Parent.Parent.Parent.Song1.Visible == true then
        script.Parent.Parent.Parent.Parent.Song2.Visible = true
        script.Parent.Parent.Parent.Parent.Song1.Visible = false
    end
            if script.Parent.Parent.Parent.Parent.Song2.Visible == true then
        script.Parent.Parent.Parent.Parent.Song3.Visible = true
        script.Parent.Parent.Parent.Parent.Song2.Visible = false
    end
end)

1 answer

Log in to vote
1
Answered by 10 years ago

First of all, check in Studio in the Script if there are any red underlined areas. If there are, hover over them. From what I can tell, you should name the Function. Also, all of those "Parents" is almost always a recipe for disaster. If I were you, I would do something like this (I'll highlight the areas I changed):

bin = script.Parent.Parent.Parent.Parent --Alternatively, you can use game.StarterGui etc etc, I'm just not sure what your model setup is

script.Parent.MouseButton1Down:connect(function(onClicked) --Named the function
    script.Parent.Parent.Parent.Parent.PlayerLocalSound:Stop()
    if script.Parent.Parent.Parent.Parent.SongOne.Visible == true then --You can't use numbers in ModelNames for scripts, it reads it as something else. Keep it to words only
        script.Parent.Parent.Parent.Parent.SongTwo.Visible = true
        script.Parent.Parent.Parent.Parent.SongOne.Visible = false
    elseif script.Parent.Parent.Parent.Parent.SongTwo.Visible == true then --Rather than ending the if, use elseif, it's a lot more efficient
        script.Parent.Parent.Parent.Parent.SongThree.Visible = true
        script.Parent.Parent.Parent.Parent.SongTwo.Visible = false
    else
    print("An error has occurred.") --This makes sure that nothing is going wrong with your models, be sure to check your output
    end
end)

All in all, you basically just have some very messy coding that probably is screwing up due to all the Parents.

Note: I'm no experienced coder, I just saw some things that I thought might help. This isn't guaranteed to work. If you add a screenshot of your Explorer setup here, then I can help some more.

Ad

Answer this question