So I’m trying to do my notification GUI visible for all the players but the problem is the script is not making the GUI visible.
My goal is make a Notification GUI when I click a button.
Here is a screenshoot of my current script. https://gyazo.com/fb82af5c1fdcaf1f52979ed9b17a5d38
I hope someone help me, thank you!
It preferred by most people to post the actual code in a codeblock, rather than posting a screenshot of it.
Here is code that would work:
function Alert()
local player = game.Players.LocalPlayer
local ui = player.PlayerGui.Notification
ui.Enabled = true
end
The issue with your code is that you’re assigning a variable called gui to a Boolean returned from the equation - it wasn’t actually changing the visibility of the ui
Normal scripts don’t have a LocalPlayer because they aren’t tied to a specific client, but the Roblox server.
@rokec123 The server (or a normal/server script) can’t access the descendants of PlayerGui, as the entire StarterGui is cloned on the client and is in respect to FilteringEnabled, unless it is actually cloned from the server
The solution would be to use a local script in StarterPlayer/Character Scripts, reference the part in the workspace and connect the function to the event:
local player = game.Players.LocalPlayer
local part = -- the part's location
function Alert()
player.PlayerGui.Notification.Enabled = true
end
part.ClickDetector.MouseClick:Connect(Alert)
Yes, in case you want to make it visible for everyone, loop through all players and make it visible.
local players = game:GetService("Players")
function Alert(player)
for i, v in pairs(players:GetPlayers()) do
local ui = v.PlayerGui.Notification
ui.Enabled = true
end
end