Show Player Name That clicked the Gui To all Clients

Hello, I’m trying to make a Notification Button/Gui that shows the name of the player who clicked the button.

I already made the Button that shows a Gui to All clients. I’m only missing the code that shows the player name who clicked the Button.

Here are my scripts:

Local Script inside of TextLabel:


local Players = game:GetService("Players")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer

local newPlayerEvent = ReplicatedStorage:WaitForChild("CAUGHT_IN_4K_BACKROOMS1")

local playerGui = player:WaitForChild("PlayerGui")

local ploppy = script.Parent

local function onNewPlayerFired()

ploppy.Visible = true

ploppy.Text = "Caught in 4k 😳 📸 --> "..player.Name

wait(6)

ploppy.Visible = false

end

newPlayerEvent.OnClientEvent:Connect(onNewPlayerFired)

Local Script that Shows Notification:


local Player = game:GetService("Players").LocalPlayer

local function callback(Text)

if Text == "yes" then

print(Player.Name)

game.ReplicatedStorage.CAUGHT_IN_4K_BACKROOMS:FireServer()

elseif Text == ("bruh") then

print ("NEVER GONNA GIVE YOU UP")

end

end

local NotificationBindable = Instance.new("BindableFunction")

NotificationBindable.OnInvoke = callback

while true do

wait(10)

game.StarterGui:SetCore("SendNotification", {

Title = "Sans";

Text = "Placeholder";

Icon = "http://www.roblox.com/asset/?id=5018130938";

Duration = "10";

Button1 = "yes";

Button2 = "bruh";

Callback = NotificationBindable;

})

end

ServerSide Script:


local Players = game:GetService("Players")

local Player = game:GetService("Players").LocalPlayer

local newPlayerEvent = game.ReplicatedStorage.CAUGHT_IN_4K_BACKROOMS1

local sans = game.Workspace.Sans

bruh = true

game.ReplicatedStorage.CAUGHT_IN_4K_BACKROOMS.OnServerEvent:Connect(function(player)

game.Workspace.Alerted:Play()

newPlayerEvent:FireAllClients()

print(Player.Name)

end)

…Maybe sending LocalPlayer also…?
(Printing name in console indeed)

But how do you do that? That’s the purpose of this topic.

Simply add the player parameter when firing all clients:

SERVER SCRIPT

game.ReplicatedStorage.CAUGHT_IN_4K_BACKROOMS.OnServerEvent:Connect(function(player)

game.Workspace.Alerted:Play()

newPlayerEvent:FireAllClients(player)

end)

LOCAL SCRIPT

local function onNewPlayerFired(player)

ploppy.Visible = true

ploppy.Text = "Caught in 4k 😳 📸 --> "..player.Name

wait(6)

ploppy.Visible = false

end

newPlayerEvent.OnClientEvent:Connect(onNewPlayerFired)

By the way, you don’t have to use the same event/function name as in the documentation, you can just change the name to notificationFunc() or something like that.

1 Like

There is already a topic about this on the devforum. Please look if there’s already a solution available, and only make a new topic in case you couldn’t find one.

1 Like

thx, always wondered why people added (player).

1 Like