Private chat message not sending?

Hey everyone, I’m trying to send a private chat message to players that own a gamepass. Below is my local script. The debug says this error: SendMessage is not a valid member of Player "Players.UnderCity21" Does anyone know why this isn’t working?

localscript in StarterPlayer in StarterPlayerScripts:

game.ReplicatedStorage.TheLodgeRobberyOpen.OnClientEvent:Connect(function()
	local player = game:GetService("Players").LocalPlayer
	if player.Team == game.Teams["Criminal"] or player.Team == game.Teams["Citizen"] or player.Team == game.Teams["Prisoner"] then
		if player.CriminalPass.Value == 1 then-- Checks if the player has gamepass
			local message = "Criminal Pass: The Lodge Can Be Robbed! Time: " .. game.StarterGui.Time.TextLabel.Text
			player:SendMessage(message,"All",{ChatColor = Color3.new(1,0,0)})
		end
	end
end)
1 Like

The issue is here :
player:SendMessage(message,"All",{ChatColor = Color3.new(1,0,0)})

Plus, to check if a player has a gamepass, you could do :

if game:GetService("MarketPlaceService"):UserOwnsGamePassAsync(player.UserId,YOUR_PASS_ID) then
    --do code here
end

Could you show the Server Script aswell?

1 Like

If I understood you right, you want to send messages to only players that own a gamepass,

There are several ways to do so,

One of them, is to make a button + text box, and invoke the text to the server and then show it to all players who own the gamepass. On the chat.

1 Like

It checks if the player has a game pass already in a different script. It checks if it has it here by checking a player’s value. Here is the script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TheLodgeRob = ReplicatedStorage:WaitForChild("TheLodgeRob")
local TheLodgeWaitAlert = ReplicatedStorage:WaitForChild("TheLodgeWaitAlert")
local TheLodgeRobberyOpen = ReplicatedStorage:WaitForChild("TheLodgeRobberyOpen")
local badgeservice = game:GetService("BadgeService")
local Ran = false
local Skip = false
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
	local id = 21276446
	local Prize = 0
	if game:GetService("GamePassService"):PlayerHasPass(player, id) then
		if game:GetService("GamePassService"):PlayerHasPass(player, 35004048) then
			Prize = 1000
		else
			Prize = math.random(750, 1000)
		end
	else
		--game:GetService("MarketplaceService"):PromptGamePassPurchase(player, id)
		if game:GetService("GamePassService"):PlayerHasPass(player, 35004048) then
			Prize = 500
		else
			Prize = math.random(250, 500)
		end
	end
	if player.Team == game.Teams["Police"] then
		game.ReplicatedStorage.TheLodgeRobPolice:FireClient(player)
		script.Parent.ProximityPrompt.Enabled = false	
		wait(3.65)
		script.Parent.ProximityPrompt.Enabled = true
		do return end
	end
	if player.Team == game.Teams["Prisoner"] then
		do return end
	end
	if player.Team == game.Teams["Criminal"] then
	end
	if player.Team == game.Teams["Citizen"] then
		Ran = true
		if not badgeservice:UserHasBadgeAsync(player.UserId, 2125306849) then
			badgeservice:AwardBadge(player.UserId, 2125306849)
		end
		if Skip == true then
			Skip = false
			do return end
		end
		player.Team = game.Teams['Criminal']
		game.ReplicatedStorage.FirstRobbery:FireClient(player)
	end
	if player.Team == game.Teams["Criminal"] or player.Team == game.Teams["Citizen"] then
		Ran = false
		game.ReplicatedStorage.TheLodgeRobSuccess:FireClient(player)
		TheLodgeRob:FireAllClients(player.Name, Prize)
		badgeservice:AwardBadge(player.UserId, 2125306833)
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + Prize
		player.Bounty.Value = player.Bounty.Value + 500
		script.Parent.ProximityPromptWait.Enabled = true
		script.Parent.ProximityPrompt.Enabled = false	
		wait(300)
		script.Parent.ProximityPrompt.Enabled = true
		script.Parent.ProximityPromptWait.Enabled = false
		TheLodgeRobberyOpen:FireAllClients()
	end
end)

script.Parent.ProximityPromptWait.Triggered:Connect(function(player)
	if player.Team == game.Teams["Criminal"] or player.Team == game.Teams["Citizen"] then
		game.ReplicatedStorage.TheLodgeWaitCC:FireClient(player)
		TheLodgeWaitAlert:FireAllClients(player.Name)
	end
	if player.Team == game.Teams["Police"] then
		game.ReplicatedStorage.TheLodgeWait:FireClient(player)
	end
end)
1 Like

Well the local script waits until that remote event is fired, and when its fired it goes to all clients and then on every client it finds out if that player has the gamepass. That’s not the issue the issue is that the message isn’t sending and I don’t know why. Edit: It’s making a private chat message to that player.

First, instead of using wait(300), use task.wait() - it’s more efficient and more accurate.

2- Could you format the code? So it could be easier to see

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TheLodgeRob = ReplicatedStorage:WaitForChild("TheLodgeRob")
local TheLodgeWaitAlert = ReplicatedStorage:WaitForChild("TheLodgeWaitAlert")
local TheLodgeRobberyOpen = ReplicatedStorage:WaitForChild("TheLodgeRobberyOpen")
local badgeservice = game:GetService("BadgeService")
local Ran = false
local Skip = false
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
	local id = 21276446
	local Prize = 0
	if game:GetService("GamePassService"):PlayerHasPass(player, id) then
		if game:GetService("GamePassService"):PlayerHasPass(player, 35004048) then
			Prize = 1000
		else
			Prize = math.random(750, 1000)
		end
	else
		--game:GetService("MarketplaceService"):PromptGamePassPurchase(player, id)
		if game:GetService("GamePassService"):PlayerHasPass(player, 35004048) then
			Prize = 500
		else
			Prize = math.random(250, 500)
		end
	end
	if player.Team == game.Teams["Police"] then
		game.ReplicatedStorage.TheLodgeRobPolice:FireClient(player)
		script.Parent.ProximityPrompt.Enabled = false	
		wait(3.65)
		script.Parent.ProximityPrompt.Enabled = true
		do return end
	end
	if player.Team == game.Teams["Prisoner"] then
		do return end
	end
	if player.Team == game.Teams["Criminal"] or player.Team == game.Teams["Citizen"] then
		game.ReplicatedStorage.TheLodgeRobSuccess:FireClient(player)
		TheLodgeRob:FireAllClients(player.Name, Prize)
		badgeservice:AwardBadge(player.UserId, 2125306833)
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + Prize
		player.Bounty.Value = player.Bounty.Value + 500
		script.Parent.ProximityPromptWait.Enabled = true
		script.Parent.ProximityPrompt.Enabled = false	
		task.wait(300)
		script.Parent.ProximityPrompt.Enabled = true
		script.Parent.ProximityPromptWait.Enabled = false
		TheLodgeRobberyOpen:FireAllClients()-- This is what fires to all clients after 300 seconds.
	end
end)

Does this help?

Yes. I’ll come back in 5-10 minutes,
maybe someone else would come meanwhile and help, I took a look at your code, be right back.

1 Like

Never mind I found a different solution. If you send the message as a chat message then it sends the message but its local meaning only you can see it!

example in local script in starterplayerscripts:

StarterGui:SetCore("ChatMakeSystemMessage", {
			Text = "This is a system message"; --The chat message
			Color = Color3.fromRGB(0, 255, 255); --Chat message color, defaults to white
			Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
			TextSize = 18 --Text size, defaults to 18
		})