Custom Join Message isn't working as expected

Hello, Scripters.
The issue is when someone joins it says a normal join message, but when a Dev joins.
It should say a custom chat message, but the developer message, it says for everyone who joins.

Client Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local PlayerEvent = Remotes:WaitForChild("PlayerEvent")
local StarterGui = game:GetService("StarterGui")

PlayerEvent.OnClientEvent:Connect(function(player, developer)
	if developer == false then
		StarterGui:SetCore("ChatMakeSystemMessage", {
			Text = player.DiplayName.. " Has Joined The Game 👋",
			Color = Color3.fromRGB(212, 212, 212),
			Font = Enum.Font.SourceSans,
			FontSize = Enum.FontSize.Size11
		})
	end
	
	if developer == true then
		StarterGui:SetCore("ChatMakeSystemMessage", {
			Text = "A Developer Has Joined The Game. Greetings "..player.DisplayName.. " 👋" ,
			Color = Color3.fromRGB(255, 0, 0),
			Font = Enum.Font.Sarpanch,
			FontSize = Enum.FontSize.Size8
		})
	end
	
	
end)

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local PlayerEvent = Remotes.PlayerEvent


game.Players.PlayerAdded:Connect(function(player)
	if player.UserId == 1 or 2  then --Example User IDs
		PlayerEvent:FireAllClients(player, true)
	else
		PlayerEvent:FireAllClients(player, false)
	end
end)

Plus, when using ‘FireAllClients’, no need to provide the Player as an argument. It automatically fires it to all players in-game. But I assume you want to use their name,so try this :

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local PlayerEvent = Remotes.PlayerEvent


game.Players.PlayerAdded:Connect(function(player)
	if player.UserId == 1 or 2  then --Example User IDs
		PlayerEvent:FireAllClients(player.name,true)
	else
		PlayerEvent:FireAllClients(player.name,false)
	end
end)

--CLIENT

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local PlayerEvent = Remotes:WaitForChild("PlayerEvent")
local StarterGui = game:GetService("StarterGui")

PlayerEvent.OnClientEvent:Connect(function(playerName,developer)
	if developer == false then
		StarterGui:SetCore("ChatMakeSystemMessage", {
			Text =  playerName.."Has Joined The Game 👋",
			Color = Color3.fromRGB(212, 212, 212),
			Font = Enum.Font.SourceSans,
			FontSize = Enum.FontSize.Size11
		})
	end
	
	if developer == true then
		StarterGui:SetCore("ChatMakeSystemMessage", {
			Text = "A Developer Has Joined The Game. Greetings "..player.. " 👋" ,
			Color = Color3.fromRGB(255, 0, 0),
			Font = Enum.Font.Sarpanch,
			FontSize = Enum.FontSize.Size8
		})
	end
	
	
end)

1 Like

I presume that is happening because of the first conditional statement in the server script:

First, it checks if the player’s UserId is equal to the first number but it doesn’t do that for the second one. When it reaches or 2, it’ll evaluate to true because from what I understand, Lua treats all numbers as a true value. *(Refer to the resource at the bottom of this post for more info)

In order to resolve this, you can either check it again, like so:

if player.UserId == 1 or player.UserId == 2 then

Or if you have more than two players, you can place all of the UserIds into a table so that it’s much more concise:

local developers = {1, 2, 3}

...

if table.find(developers, player.UserId) then
    -- Continue

Additional Resources

Lua 5.1 Reference Manual - Section 2.4.4

Direct quote from that section:

All values different from nil and false are considered true (in particular, the number 0 and the empty string are also true).

1 Like

Thank you @StrongBigeMan9 and @Valkyrop for helping me.

1 Like