I am making a game where every round is like a race and I want there to be a notification for every player when a player crosses the finish line. Like in the upper right hand corner it will say “Emrek has finished” stay there for a second then it will fade away. I could probably figure out how to do this on my own but some rounds could have 20+ players and if multiple players finish at the same time the notifications could look really cluttered and you wouldn’t be able to see the names of the players because there is so much overlay of text. So I thought it would be best to make a system so that once a notification starts no other notifications will play and if someone finished during this time they will be added to a waitlist until all the other notifications in front of them have finished playing. I already have remote events that tell the server everytime a player finished so I don’t have to worry about that, I just don’t know where to start with a system like this, any ideas on what I should do?
Ok, I finished making a ModuleScript that makes notifications. Also, I don’t recommend sending another notification while another one is already there.
local module = {}
function module.notifyPlayer(Plr:Player,Title:string,Message:string,TimeShown:number,FillColor:Color3,OutlineColor:Color3,TimeBarColor:Color3,TitleColor:Color3,MessageColor:Color3,TitleFont:Enum.Font,MessageFont:Enum.Font)
local ScreenGui = Instance.new('ScreenGui')
ScreenGui.ResetOnSpawn = false
ScreenGui.Enabled = true
ScreenGui.Parent = Plr.PlayerGui
local Frame = Instance.new('Frame')
Frame.AnchorPoint = Vector2.new(1,1)
Frame.Position = UDim2.fromScale(.991,.98)
Frame.Size = UDim2.fromScale(.12,.123)
Frame.BorderSizePixel = 5
Frame.BackgroundColor3 = FillColor
Frame.BorderColor3 = OutlineColor
Frame.Parent = ScreenGui
local TimeBar = Instance.new('Frame')
TimeBar.Position = UDim2.new(0,0,0,0)
TimeBar.Size = UDim2.fromScale(1,.069)
TimeBar.BackgroundColor3 = TimeBarColor
TimeBar.Parent = Frame
local LabelTitle = Instance.new('TextLabel')
LabelTitle.Text = " " .. Title
LabelTitle.TextColor3 = TitleColor
LabelTitle.Font = TitleFont
LabelTitle.Position = UDim2.fromScale(0,.062)
LabelTitle.Size = UDim2.fromScale(1,.3)
LabelTitle.BackgroundTransparency = 1
LabelTitle.TextXAlignment = Enum.TextXAlignment.Left
LabelTitle.TextScaled = true
LabelTitle.BorderSizePixel = 0
LabelTitle.Parent = Frame
local LabelMessage = Instance.new('TextLabel')
LabelMessage.Text = Message
LabelMessage.TextColor3 = MessageColor
LabelMessage.Font = MessageFont
LabelMessage.Position = UDim2.fromScale(0,.3)
LabelMessage.Size = UDim2.fromScale(1,.7)
LabelMessage.BackgroundTransparency = 1
LabelMessage.TextXAlignment = Enum.TextXAlignment.Left
LabelMessage.TextYAlignment = Enum.TextYAlignment.Top
LabelMessage.TextScaled = true
LabelMessage.BorderSizePixel = 0
LabelMessage.Parent = Frame
TimeBar:TweenSize(
UDim2.new(0,0,0,TimeBar.AbsoluteSize.Y),
Enum.EasingDirection.Out,
Enum.EasingStyle.Linear,
TimeShown,
true
)
task.wait(TimeShown)
ScreenGui:Remove()
end
return module
This is an example of how to use it.
local Module = require(script.ModuleScript)
game.Players.PlayerAdded:Connect(function(Plr)
task.wait(1)
print('notified')
Module.notifyPlayer(
Plr, ----------------------------> Player to notify
'Notification', -----------------> Title of the notification
'Hello!', -----------------------> Message of the notification
10, -----------------------------> Time it will stay on screen for
Color3.fromRGB(33,33,33), -------> Background color of the notification
Color3.fromRGB(22,22,22), -------> Outline color of the notification
Color3.fromRGB(140,209,255), ----> Time Bar color of the notification
Color3.fromRGB(255,255,255), ----> Text Color of the Title
Color3.fromRGB(255,255,255), ----> Text Color of the Message
Enum.Font.Nunito, ---------------> Font of the Title
Enum.Font.Nunito ---------------> Font of the Message
)
end)
For the waitlist, maybe use a list for the people whose names haven’t been displayed, and a separate list for names which have been displayed. Then loop through the first list, displaying the name, adding to the second list and having a cooldown. Something like this:
local finishRemote = game.ReplicatedStorage.remotes.FinishRemote-- Add your remoteevent here for when someone finishes
local notificationRemote = game.ReplicatedStorage.remotes.NotificationRemote -- Add a remoteevent here to send notification to players
local toDisplay = {}
local haveDisplayed = {}
local function updateList()
for i, player in pairs(toDisplay) do
print("2")
table.remove(toDisplay, i)
-- Add notification
notificationRemote:FireAllClients(player)
table.insert(haveDisplayed, player)
end
end
finishRemote.OnServerEvent:Connect(function(player)
print("1")
table.insert(toDisplay, player.Name)
updateList()
end)
“finishRemote” being your remote event that tells the server when someone finishes.
“notificationRemote” being a new remote event which is sent to players to create a notification using a method such as the one which @calvin_coco provided
It looks like through this I can only send the notification to one player what if I wanted to send it to all the players in the game?
If you want it to send it to all players, then iterate over all the players and notify them.
for _, plr in game.Players:GetPlayers() do
Module.notifyPlayer(
Plr,
'Notification',
'Hello!',
10,
Color3.fromRGB(33,33,33),
Color3.fromRGB(22,22,22),
Color3.fromRGB(140,209,255),
Color3.fromRGB(255,255,255),
Color3.fromRGB(255,255,255),
Enum.Font.Nunito,
Enum.Font.Nunito
)
end
Edit: If you want it to be different for 1 person, then check if the plr
is equal to another plr