GUI Visibility Issue

Hello!

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!

Where is your script located and what type of script is it?

  1. It preferred by most people to post the actual code in a codeblock, rather than posting a screenshot of it.

  2. 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

2 Likes

Normal script and It’s located into a part (button), and the button is located inside of a model.
https://gyazo.com/2556ee093f71ea1d24fd40645ecef567

Since this is a regular script, you can’t get the local player, .MouseClick event has an argument telling you which player has clicked the object.

function Alert(player)
    local ui = player.PlayerGui.Notification
    ui.Enabled = true
end
2 Likes

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)
1 Like

Yes, the server can access descendants of PlayerGui.

1 Like

But that will make the GUI visible only for the person who clicked it?

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

Thank you so much, It worked. :slight_smile:

No problem, it’s my pleasure to help you!

1 Like