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

Why my buttons with local script dont make shop frame visible/invisible?

Asked by 2 years ago

Output says: Players.SashaPro336.PlayerGui.Shop.Frame.TextButton.LocalScript:4: invalid argument #1 to 'Connect' (RBXScriptSignal expected, got function)

The buttons local scripts:

button = script.Parent
shop = game.StarterGui.Shop.Frame

button.MouseButton1Click.Connect(function()
shop.Visible = true     --On other button false--
end)

2 answers

Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
2 years ago

I see the issue. Simple syntax error. Connect has a colon, not a period.

Also, you must use a local script. Each player has a "PlayerGui" which you must reference.

--Put this LocalScript inside the GUI

button = script.Parent
shop = game.Players.LocalPlayer.PlayerGui.Shop.Frame --You must reference the players PlayerGui

button.MouseButton1Click:Connect(function()
    shop.Visible = true 
end)

Have a good day!

0
Thank so much SashaPro336 47 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Hello, this was a mistake I did when I first started out so I am trying to explain it as I would to myself. So basicaly you have defined StarterGui and that is incorrect because the starterGui is just for the server to give the gui's to the players so when someone joins they get something called a PlayerGui and in there all the gui's form starterGui transfer.

Read More here: https://developer.roblox.com/en-us/api-reference/class/PlayerGui I also recommend to watch this video: https://www.youtube.com/watch?v=IFAVIFAHAxY&list=PLhieaQmOk7nK9ob348Yc_PTcIyHjDCnem&index=2&ab_channel=TheDevKing

button = script.Parent -- this will be your TextButton
shop = game.StarterGui.Shop.Frame -- This is actually not the player's gui this is the gui that every player gets to explain it further StarterGui Is basically just a storage for all the gui's and when a player joins he gets a copy of the gui in StarterGui

button.MouseButton1Click.Connect(function()

    shop.Visible = true     -- so this is actually referering to StarterGui (server) insted of PlayerGui Witch is for the player // client.

end)


-- Solution

button = script.Parent -- TextButton

button.MouseButton1Down:Connect(function(player) -- in this argument we are passing player wich just means we get his game.Players.playernamehere

    local OurPlayersGui = player.PlayerGui.Shop.Frame -- this is where the gui for the player is

    OurPlayersGui.Viseble = true -- makes it so you can see the frame

end)

If there was anything you didnt understand please tell me and I will try better If it did help you please accept my answer.

0
Output says: Players.SashaPro336.PlayerGui.Shop.ShopButton.LocalScript:5: attempt to index number with 'PlayerGui' SashaPro336 47 — 2y
0
So can you help me SashaPro336 47 — 2y
0
I just helped you what do you mean? johnoscarbhv1 137 — 2y
0
From line 13-21 is the answer johnoscarbhv1 137 — 2y
0
i mean it didnt work output said Players.SashaPro336.PlayerGui.Shop.ShopButton.LocalScript:5: attempt to index number with 'PlayerGui'. Idk what to do SashaPro336 47 — 2y

Answer this question