Need help with making a invisible frame visible with a button

Hi there! I am a newbie developer making a game but i am having trouble with scripting. I am trying to make a frame visible when a button is pressed but it doesn’t seem to be working.

Here is the script i use and the error i keep on receiving:

I do not know what the error means and how to fix it. I tried everything i could and it still will not work.

Here is a video to show the error i keep getting:

Here is a photo of where the script, the button and the frame are located:Annotation 2020-04-18 215411

Does anyone know what i did wrong? I really need help with fixing this.
Thanks!

6 Likes

This is due to FE (Filtering Enabled) the way to fix this is to use a Remote Event.

This has happened to me at least once so I know what to do here’s what you need to do:

  • Create a new Remote Event inside of ReplicatedStorage and name it whatever you want, don’t forget to change the RemoteEvent variable that we will be getting inside of every Local Script/Script that we will be getting.
  • Reference your Remote Event in a Local Script inside the StarterGui and like so:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("REMOTE_EVENT_NAME_HERE")

script.Parent.ShopButton.MouseButton1Click:Connect(function()
    RemoteEvent:FireServer()
end)
  • Create a new Script in ServerScriptService and then use :FireClient() like so:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("REMOTE_EVENT_NAME_HERE")

RemoteEvent.OnServerEvent:Connect(function()
    RemoteEvent:FireClient()
end)

NOTE: If you want to update the frame’s visiblity to all players use RemoteEvent:FireAllClients() instead.

  • Now create an another Local Script inside of StarterGui and update the frame’s visibility from there like so:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("REMOTE_EVENT_NAME_HERE")

local frame = script.Parent

RemoteEvent.OnClientEvent:Connect(function()
    frame.Visible = true
end)

And there you go it should be working perfectly fine now, if anything goes wrong don’t hesitate to tell me, if it’s the solution then mark it as the solution so other people know that this post fixed the problem.

Try : local function click (player)
script.Parent.Visible = true
end)
script.Parent.MouseClick:Connect(click)

Shopbutton is located inside the ScreenGui, not the frame, so you would define it as

Script.Parent.Parent.Shopbutton

Also, the frame would be

Script.Parent

Also, @Nerkonl, you wouldn’t use RemoteEvents because it is all handled in the client.

1 Like

he does not need to use Remote events for this, because opening and closing that UI can be handled by the client and does not need the server to know about it.

What he did wrong was pathing the frame and the button, so if I read the post properly, here is the solution.

Solution:

local frame = script.Parent

script.Parent.Parent.ShopButton.MouseButton1Click:Connect(function()
     frame.Visible = not frame.Visible
end)
10 Likes

I have done everything you listed in the comment. I made the RemoteEvent, i put the script:

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local RemoteEvent = ReplicatedStorage:WaitForChild(“REMOTE_EVENT_NAME_HERE”)

script.Parent.ShopButton.MouseButton1Click:Connect(function()
RemoteEvent:FireServer()
end)

in both the LocalScript and made a new script with the same thing (the REMOTE_EVENT_NAME_HERE part not included, replaced it with the name i set for the Remote Event.)

Use @photonavius 's script. If it works, make his post the solution.

2 Likes

Thank you! It works now :slight_smile:

No problem! Glad I could help.

2 Likes

Your correct but it’s honestly good practice to use Remote Events because of FE.

1 Like

Not when you are opening and closing Gui which can easily be handled in the client and is also much faster.

Not in this case. The UI above is only visible to the person who interacts with it. The server is concerned with all the players. The server is not needed in this case, and this can and should be completed entirely clientside.

Now, if we were to require information from the server that the client cannot access, or we need to send data to multiple clients, then yes, FE would be your best bet on communicating with the server/clients.

1 Like

Yes I get what you mean but what I was saying is what if he wanted to update it to everyone else?

He’s using a Local Script so obviously it will only update for the player that clicked on the button and not everyone.

He can achieve this by using :FireAllClients() like I mentioned in my first post in this thread, you need to practice how to use Remote Events in the cases of these and also Remote Functions, not everything will work as intended without Remote Events and Remote Functions i’m just giving him a pro tip.

This is getting off-topic, so this will be the last post. This is simply just an open/ close script that works client-sided which the server doesn’t need to no about. I get your point but RemoteEvents are unneeded in this case.