local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local welcomePlayerEvent = Instance.new("RemoteEvent")
welcomePlayerEvent.Parent = ReplicatedStorage
welcomePlayerEvent.Name = "WelcomePlayerEvent"
local function onPlayerAdded(player)
welcomePlayerEvent:FireClient(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
My current client code
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local welcomePlayerEvent = ReplicatedStorage:WaitForChild("WelcomePlayerEvent")
local playerGui = player:WaitForChild("PlayerGui")
local welcomeScreen = Instance.new("ScreenGui")
welcomeScreen.Parent = playerGui
local welcomeMessage = Instance.new("TextLabel")
welcomeMessage.Size = UDim2.new(0, 200, 0, 50)
welcomeMessage.Parent = welcomeScreen
welcomeMessage.Visible = false
welcomeMessage.Text = "Welcome to the game!"
local function onWelcomePlayerFired()
welcomeMessage.Visible = true
task.wait(3)
welcomeMessage.Visible = false
end
welcomePlayerEvent.OnClientEvent:Connect(onWelcomePlayerFired)
I got this from roblox documentation, but Im getting Infinite yield possible on 'ReplicatedStorage:WaitForChild("WelcomePlayerEvent")'
game.Player.PlayerAdded:Connect(function(player)
local WelcomePlayerAddedEvent = Instance.new("RemoteEvent")
WelcomePlayerAddedEvent.Name = "WelcomePlayerAddedEvent"
WelcomePlayerAddedEvent.Parent = game.ReplicatedStorage
-- None of this needs to be done because you can already have the remote event in the replicated storage then just get the event name from here
game.ReplicatedStorage.WelcomePlayerAddedEvent:FireClient(player)
-- OR: Already have the event in the replicated storage so all you have to do is this:
game.ReplicatedStorage.WelcomePlayerAddedEvent:FireClient(player)
end)
Client Code:
-- Note that using instance is not needed when you can already have the textlabel in a screengui
game.ReplicatedStorage.WelcomePlayerAddedEvent.OnClientEvent:Connect(function()
local Message = Instance.new("ScreenGui")
Message.Name = "Message"
Message.Parent = game:GetService("Players").LocalPlayer.PlayerGui
MessageText = Instance.new("TextLabel")
MessageText.Name = "MessageText"
MessageText.Parent = game:GetService("Players").LocalPlayer.PlayerGui.Message
MessageText.Size = Udim2.new(0 ,200, 0, 50)
MessageText.Position = --Set Pos
MessageText.Visible = true
wait(3)
MessageText.Visible = false
end)
That should work but you don’t need to use Instance to make things, you should already have them placed. ex: the event in replicated storage and screengui and textlabel in the startergui