keep on trying to make guys with scripting but I can’t figure what I’m doing wrong, this is the script I’m using
- You have to be using a LocalScript to provide input.
this is just to make sure you are using it.
Edit: This doesn’t work. Why doesn’t this work though, it’s so weird… - You have to use
game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true
, not your current line,game.StarterGui.ScreenGui.Frame.Visible = true
. This is becauseStarterGui
replicates Gui’s that the player can actually interact with to thePlayerGui
in the player. It doesn’t all stay in one service, although that would be very useful actually.
You need to use a RemoteEvent so the global Script can connect with the LocalScript. In ReplicatedStorage, add a RemoteEvent. Name the RemoteEvent whatever you want. Once you do that, call it. The Script in the brick should look something like this:
-- Variables --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("GUIEnablerEvent") -- "GUIEnablerEvent" is just an example name that I named my event. If your event has another name, change the name of "GUIEnablerEvent" to the event's name.
local Brick = script.Parent
local ClickDetector = Brick:WaitForChild("ClickDetector")
-- Scripting --
ClickDetector.MouseClick:connect(function(Player)
Event:FireClient(Player)
end)
Then, add a LocalScript into the GUI you want to open up, and use something similar the following script:
-- Variables --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("GUIEnablerEvent") -- "GUIEnablerEvent" is just an example name that I named my event. If your event has another name, change the name of "GUIEnablerEvent" to the event's name.
local GUI = script.Parent
local Frame = GUI:WaitForChild("Frame")
-- Scripting --
Event.OnClientEvent:connect(function()
Frame.Visible = true
end)
You can change it however you want, but this is just the basic idea of how to do it. Just make the server communicate with the client using a RemoteEvent. This is how to do it. Here, you can see a GIF of it in action: https://gyazo.com/73b2caa1b6b59fe8fed123db8160981f.
I made a file which you can download and use here with all the scripts and parts: ClickBrickToEnableGUI.rbxl (18.4 KB)
I hope this helped you and solved your problem.
If you don’t need a server script you can just run it locally
local Player = game.Players.LocalPlayer
local Frame = Player.PlayerGui.ScreenGui.Frame
local ClickDetector = workspace.WhereverItIs
ClickDetector.MouseClick:Connect(function(plr)
if (plr == Player) then
Frame.Visible = not Frame.Visible
end
end)
I agree. If you want to run it locally and not have the RemoteEvent stuff get in your way, you can just use the @deedubbleyew’s script above. Also if you do not know what this part does,
It pretty much makes the visibility of the GUI exactly the reverse of what it is, so if it is enabled, it will become disabled, and if it is disabled, it will become enabled.
Great way. It didn’t even pop in my mind that you could just run the code from a LocalScript directly.
hey, where do I put the local script?
i can’t figure out where I’m quite new to scripting
You are doing a couple of things wrong but they can be fixed easily.
Best solution
First of all you should use RemoteEvents like other people are saying in this thread. A RemoteEvent allows you to communicate between the client server boundary. The OP has wrote a nice piece of code that solves your issue with RemoteEvents. Using RemoteEvents is the best way to solve your issue.
What you are doing wrong
Before I say what you are doing wrong I am going to say a bit of background knowledge about gui’s. A gui is a local object and that means only the client(player) can see it. This means that any modification must be done locally by using LocalScripts. A LocalScript differs from a script because a LocalScript can only be ran on the client and a script can only run on the server. When the client joins the game all of the gui’s in StarterGui in short get copyed and pasted into the client. The folder they go into on the player is called PlayerGui. This brings me onto what you are doing wrong.
On your current code you are not saying what player the gui needs to open up on. Here is simple fix to your solution if you want to only do this server side. However this is not the best solution but it will make explaining what you are doing wrong easier:
local ClickDetector = script.Parent.ClickDetector
ClickDetector.MouseClick:Connect(function(Player)
Player.PlayerGui.ScreenGui.Frame.Visible = true
end)
As you can see in the parameter(Pair of brackets after the function) I have said player. This basically says what player is clicking on this brick. This is very important because we want to know what player to open up the gui on.
The first line in the function is saying on the player in PlayerGui in ScreenGui open up the frame. On your piece of code you haven’t even said what player to open up the gui on. Also you have used StarterGui instead of PlayerGui.
MouseButton1Click maybe will work but u have a click detector so im not sure
You need to put the script in StarterGui, or in the GUI itself. This is how the script will be read from the client side.
@M_walker3
MouseButton1Click can’t work for click detectors so MouseClick is the only other option.
To add a little more information to what @Batman212369 said. LocalScripts can only run on the client and scripts can only run on the server. You should never use LocalScripts on the server and scripts on the client as they wont work. A LocalScript can only run if it is a decedent of PlayerGui, Backpack, StarterGear, StarterPlayerScripts and StarterCharacterScripts.
yea i figured,remoteevents might tho ,but i never made something like this
-
You need to use a local script otherwise it won’t work.
-
You can try TweenService instead of Visible.
game.StarterGui.ScreenGui.Frame:TweenPosition(Udim2.new(//YourPositionHere)
After writing these lines you should move your UI out of the screen.
For your future post you should write the lines otherwise we can’t help you out with a screenshot
You forgot to close the parentheses :
And also it’d be better if you customized your tween with easing style, easing direction, time and the other options. TweenService roblox dev article here.
I just wanted to keep it simple. I don’t know if he knows or he doesn’t know…
hi I can’t figure out what I’m doing wrong it isn’t seeming to work
local Player = game.Players.LocalPlayer
local Frame = Player.PlayerGui.ScreenGui.Frame
local ClickDetector = workspace.clickbox
ClickDetector.MouseClick:Connect(function(plr)
if (plr == Player) then
Frame.Visible = not Frame.Visible
end
end)
this is the version i’m using the clickbox was the part where the clickdetector was in
No need for if (plr == Player) then
. Also make sure that is a local script.
This line of code needs to be changed. Also is this from a LocalScript?
Frame.Visible = not Frame.Visible
You would just change it to this:
If you want the frame to be shown:
Frame.Visible = true
If you don’t want the frame to be show:
Frame.Visible = false
Please make sure you format your code correctly the next time you post. It will make it easier to read. You can format it by using this ``` before the code.
That is irrelevant. That won’t fix the problem. Just another way of making the frame visible/invisible. Also not Frame.Visible
is better than Frame.Visible = true
or false
because it always make the frame visible or invisible related to the property. Example:
something.MouseButton1Click:Connect(function()
frame.Visible = not frame.Visible
end)
is better than
something.MouseButton1Click:Connect(function()
if frame.Visible == true then
frame.Visible = false
else
frame.Visible = true
end
end)
is workspace.clickbox a part?
If so you’ll need to fix the clickdetector variable as currently if I’m assuming correctly you’re attempting to run the MouseClick function on a regular part.
local Player = game.Players.LocalPlayer
local Frame = Player.PlayerGui.ScreenGui.Frame
local ClickDetector = workspace.clickbox.ClickDetector
ClickDetector.MouseClick:Connect(function(plr)
if (plr == Player) then
Frame.Visible = not Frame.Visible
end
end)