Hi! So recently I was trying to make a menu type thing, that has a cutscene with a chat gui thing. I have the player, clicking a button, which fires and event. So I have the rest of the code in the script that listened for the event to be fired. How should I have the game disable the menu GUI, since as far as I know, you can’t access PlayerGui from a regular script “game.Players.LocalPlayer.PlayerGui” <---- doesn’t work.
Sure! Its VERY messy right now, because I’ve been trying a bunch of different things, I’ll clean it up later.
this is a local script under the GUI button
local button = script.Parent
local event = replicatedStorage:WaitForChild("StartGame")
local players = game:GetService("Players")
button.MouseButton1Click:Connect(function()
event:FireServer(1)
end)
and this is the code that I have in the local script that I put in starterplayerscripts
local players = game.Players
local localPlayer = players.LocalPlayer
local gui = localPlayer:WaitForChild("PlayerGui")
local replicatedStorage = game:GetService("ReplicatedStorage")
local chatGui = game.StarterGui.ChatGui.Frame
local sleepGui = game.StarterGui.Sleeping
local menu = game.StarterGui.MenuGui
local event = replicatedStorage:WaitForChild("StartGame")
event.OnClientEvent:Connect(function(player, num)
print(player.Name.." fired "..event.Name)
gui.Sleeping.Enabled = true
gui.MenuGui.Enabled = false
while gui.Sleeping.Frame.BackgroundTransparency > 0 do
gui.Sleeping.Frame.BackgroundTransparency -= 0.1
end
end)
Again, please ignore all the messy, out of place stuff, I haven’t had the chance to clean it up yet, since I keep trying different things, trying to find what works.
Are you trying to enable the sleeping GUI or disable it? If you are trying to disable it then you should probably add a wait(0.1) inside your while loop or else the transparency is going to change instantly
A server needs to process the remote event and send it back to the client. Add this to a regular script in ServerScriptService:
local event = game.ReplicatedStorage:WaitForChild("StartGame")
event.OnServerEvent:Connect(function(player,num)
event:FireClient(player,num)
end)
Also, there is no need to keep the player parameter on the local script in StarterPlayerScripts since the server needs that to determine which client to send it to.
Im trying to enable the sleeping gui - basically I’m gonna have it just be a black screen that slowly becomes transparent, almost as if you were waking up (or atleast thats what I hope it looks like)
<— this is all after the player clicks the play on the menu button
Hi! So after changing these, it works now! So thank you for that!
Also, how should I go about having the sleeping gui slowly increase transparency (going from black to clear), I was thinking I could use a repeat until, but I’m not so sure.
The PlayerGui instance of a player should never be handled by the server, in this scenario I’d recommend handling everything inside of a local script (you mitigate the necessity of firing the server and then having the server refire the client which will just cause unnecessary latency issues). The PlayerGui object and its descendants all replicate to the client (and are client specific) as such they can be easily read from and manipulated from the client through the use of local scripts (modifications to a player’s PlayerGui do not need to be replicated to the server).