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

Why won't this script repeat after it happens one time?

Asked by
2_MMZ 1059 Moderation Voter
3 years ago
Edited 3 years ago

Hi, so, I'm trying to make a game for my brother, and we have basically everything done. I click on the vault to enter the code, and if you type it correctly, or exit out of it, and then try to click it again, it doesn't do what it just did before. Can I get some help on this?

clickpart script:

function onClicked(player)
print("Clickdetector was clicked!")
player.PlayerGui.ScreenGui.Frame.Visible = true
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

XButton script:

script.Parent.MouseButton1Click:Connect(function()
  script.Parent.Parent.Parent.Frame.Visible = false
end)

(The correct code script is too long so I'm not gonna put it here.)

GIF Of this happening: https://gyazo.com/9d32aa8acff85bce83aa2ca224ffe2c8

0
try using a while loop, and make the condition relate to the clicking CactusRequiem 0 — 3y
0
Please include all programs. Ziffixture 6913 — 3y
0
Please put your code into a code block. RazzyPlayz 497 — 3y
0
Dont put. 3 prant JeffTheEpicRobloxian 258 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

I assume this is happening because you're not setting the same GUI element's visibility in both scripts.

clickpart script:


function onClicked(player) print("Clickdetector was clicked!") player.PlayerGui.ScreenGui.Frame.Visible = true end script.Parent.ClickDetector.MouseClick:Connect(onClicked)

XButton script:


script.Parent.MouseButton1Down:Connect(function() script.Parent.Parent.Parent.Frame.Visible = false end)

When you click the first time, the player.PlayerGui.ScreenGui.Frame element is set as visible, so the code entry GUI becomes visible. When you click the X, you want to refer to the exact same element, so that one event makes it visible and the other invisible.

What I assume is happening is that the second (XButton) script is making the parent component of the code entry GUI invisible once it's clicked. Since the element the first script refers to (player.PlayerGui.ScreenGui.Frame) is a child of the element being set to invisible, it is hidden regardless of whether its visibility is set to true or false. This is why you can only get the GUI to show once.

The solution to this is to make sure that script.Parent.Parent.Parent.Frame and player.PlayerGui.ScreenGui.Frame end up pointing at exactly the same element. You can look at the status of all GUI elements while testing the game in roblox studio to see what happens when each script is run, and which are visible/invisible in real-time.

Also, for future reference, you can make your code nicer to look at by putting it in a code block, which you can make by clicking the blue Lua button at the top of the text editor

Ad
Log in to vote
2
Answered by
2_MMZ 1059 Moderation Voter
3 years ago

I have simply solved this problem by using a Remote Event for my GUI. I have accepted whenallthepigsfly's answer, because he was the only one to answer the question.

Answer this question