Heyy, i’m trying to make this script turn a random frame from a folder of different frames visible when a textbutton is clicked, I’ve tried rewriting it to make it clone (which wouldn’t have worked), and tried lots of ways to have it reference the visibility of a random frame, but I haven’t been able to figure out how to change the visibility of the random frame selected, so I decided to make a post about it
local GUIs = game.StarterGui.ScreenGui.Cards:GetChildren()
local players = game:GetService("Players")
script.Parent.MouseButton1Click:connect(function()
GUIs[math.random(1,#GUIs)].Visible = true
end)
Instead of #GUIS, use #GUIS:GetChildren()
I tried this, it didn’t work, I got this error:
Players.NiteTecFire.PlayerGui.ScreenGui.shufflebutton.LocalScript:8: attempt to call missing method ‘GetChildren’ of table
I’m running this from a localscript inside of a textbutton
Edit: I changed the code and it still didn’t work
GUIs[math.random(1,#GUIs:GetChildren())].Visible = true
I also tried to move the “.Visible = true” around and that didn’t work either
I see what is wrong, you are using game.StarterGui.ScreenGui.Cards:GetChildren() instead of giving the good path to the Cards thing. Use this:
local GUIs = game.Players.LocalPlayer.PlayerGui.ScreenGui.Cards:GetChildren()
Explanation: When you used game.StarterGui.ScreenGui.Cards:GetChildren(), your script was changing the ScreenGui in StarterGui thus meaning that players would not be able to see any changes.
1 Like
Thank you!! this has been racking my brain for hours, I really appreciate this!
1 Like
No problem! That’s why I’m here!
1 Like