Hello everyone
So I was testing my game and I have a part with a script and a click detector on it. On the script I have a simple system that when you click that part, a GUI (that is a shop) opens, and when you clcik a textbutton, it close. The problem here is that most of the times when you click it, it doen’s work. Here I put the scripts
-Part Script(the one to open the GUI)(is a normal script)
script.Parent.ClickDetector.MouseClick:Connect(function(player)
player:WaitForChild("PlayerGui").WorkshopGUI.Frame.Visible = true
end)
-Close GUI Button Script(is a local script)
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Visible = false
end)
Thank you for spending your time trying to fix my problem
Spideyalvaro999
A server script cannot access the players PlayerGui
, you would need to put the first script in a localscript or use a RemoteEvent
to tell a localscript to show the frame.
2 Likes
If you want to avoid remote events, you should just move the whole system to the client side (i.e Local Scripts)
1 Like
So what should I change? The local script or the script? and I wnat that GUI to open on the client not on on the server.
detect the MouseClick
event on a local script, then change the visibility of the Frame on the same script. The local script can go in StarterPlayerScripts
So I Change the script to the local script and I change the MouseClick to what? with the script I mean the script that opens the GUI
(Example, this would go in the localscript)
local ClickDetector = nil -- put clickdetector location here
local Frame = nil -- put frame location here
local CloseButton = nil -- put close button location here
ClickDetector.MouseClick:connect(function()
Frame.Visible = true
end)
CloseButton.MouseButton1Click:connect(function()
Frame.Visible = false
end)
Instead of nil I put the location or what?
Don’t change the MouseClick
, its already set up. But instead of recieving the Player who clicked and then toggling that players gui, just toggle the game:GetService("Players").LocalPlayer
s gui
for each variable replace the nil
with the location of the object
(ie)
game.Workspace.Part.ClickDetector
or
script.Parent.Parent
Ok I will try what you are saying and I will tell you if that worked
It didin’t worked
I placed this part of the script:
local ClickDetector = nil -- put clickdetector location here
local Frame = nil -- put frame location here
local CloseButton = nil -- put close button location here
ClickDetector.MouseClick:connect(function()
Frame.Visible = true
end)
on this script you see here
and I placed this other part of the script:
local ClickDetector = nil -- put clickdetector location here
local Frame = nil -- put frame location here
local CloseButton = nil -- put close button location here
CloseButton.MouseButton1Click:connect(function()
Frame.Visible = false
end)
on that local script you see here
I change the locations as you said and nothing changed
1 Like
It only needs to go in the localscript, also, did you change the values to the parts location?
But if I put all that sfuff on the local script (THAT IS THE CLOSE BUTTON LOCAL SCRIPT), what should I put on the script of the part?
The script in the part is not necessary.
Ok im trying it and I tell you if it worked or not
I did everything as you told me, deleting the script on the part, and pasting the script that you wrote me on the close button script and anything changes, should I do the remote events way, and if I do, How should I o it?
Did you change the locations (nil
) to the locations of the objects in your game?
of course, but nothing happend
Are you sure that all the values and locations are changed to the correct values?
I tried this on my computer and it worked perfectly.
proof: robloxapp-20200703-2148362.wmv (458.5 KB)
Edit: could you upload the modified version of the localscript? (the script in your close button)