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:
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.
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)
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.)
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.
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.