Right now it causes me not to see other players chats, I also get this error when I’m in a public server: TextChatService.OnIncomingMessage:MarketPlace:UserOwnsGamePassAsync() can only query local player
Here is the local script in starterplayerscripts:
local developers = {"DinoViotto", "FizzyColas", "rvsita", "ashhchuu"}
local TextChatService = game:GetService("TextChatService")
local service = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamepassId = 25949990
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
local props = Instance.new("TextChatMessageProperties")
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if table.find(developers, player.Name) then
props.PrefixText = "<font color='#e5d415'>[🔨] [Developer]</font> " .. message.PrefixText
end
if service:UserOwnsGamePassAsync(player.UserId, gamepassId) then
props.PrefixText = "<font color='#d4af37'>[👑] [VIP]</font> " .. message.PrefixText
end
end
return props
end
Make it a normal script and place it into ServerScriptService.
Also, you should be using UserIds instead of your developer’s names so it will work even if any of your developer’s change their usernames.
Fixed code:
--//Services
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local TextChatService = game:GetService("TextChatService")
--//Controls
local gamepassId = 25949990
--//Tables
local developerIds = {
295954212,
84694314,
84398600,
1655354023
}
--//Functions
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
local props = Instance.new("TextChatMessageProperties")
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if table.find(developerIds, player.UserId) then
props.PrefixText = "<font color='#e5d415'>[🔨] [Developer]</font> ".. message.PrefixText
end
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
props.PrefixText = "<font color='#d4af37'>[👑] [VIP]</font> ".. message.PrefixText
end
end
return props
end
Oh, well :UserOwnsGamepassAsync has to be used on the server in order to access other player’s gamepass status. You need to invoke a remote function from your local script to the server so you can retrieve another player’s gamepass status.
Hi!
I know for server to client I do this in a script (IsVIP is a remote event)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteEvent = ReplicatedStorage:WaitForChild("IsVIP")
local function onPlayerAdded(player)
remoteEvent:FireClient(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
but I’m not sure how to wait for the event to fire and then implement the vip chat prefix
Edit: You should try the other post I sent as it’s more efficient, don’t do this one.
Okay, I’ll tell you steps then.
Make a LocalScript in StarterPlayerScripts and paste this inside:
--//Services
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HttpService = game:GetService("HttpService")
--//Variables
local VIPStatus = ReplicatedStorage.VIPStatus
VIPStatus.Name = HttpService:GenerateGUID(false)
VIPStatus.Parent = nil
--//Tables
local developerIds = {
295954212,
84694314,
84398600,
1655354023
}
--//Functions
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
local props = Instance.new("TextChatMessageProperties")
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if table.find(developerIds, player.UserId) then
props.PrefixText = "<font color='#e5d415'>[🔨] [Developer]</font> ".. message.PrefixText
end
VIPStatus.Parent = ReplicatedStorage
local isVIP = VIPStatus:InvokeServer(player)
VIPStatus.Parent = nil
if isVIP then
props.PrefixText = "<font color='#d4af37'>[👑] [VIP]</font> ".. message.PrefixText
end
end
return props
end
Make a new RemoteFunction in ReplicatedStorage named “VIPStatus”:
Add a new script into ServerScriptService and paste this inside:
--//Services
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local VIPStatus = ReplicatedStorage.VIPStatus
--//Controls
local gamepassId = 25949990
--//Tables
local gamepassCache = {}
--//Functions
VIPStatus.OnServerInvoke = function(player, targetPlayer)
if not targetPlayer or typeof(targetPlayer) ~= "Instance" or not targetPlayer:IsA("Player") then
return
end
local hasGamepass = gamepassCache[targetPlayer.UserId] or MarketplaceService:UserOwnsGamePassAsync(targetPlayer.UserId, gamepassId)
if not gamepassCache[targetPlayer.UserId] and hasGamepass then
gamepassCache[targetPlayer.UserId] = true
end
return hasGamepass
end
It should all work now. If there are any errors, please tell me them and I will fix it.
Another option would be to give the player an attribute called “Rank” or something on the server, then check for this rank on the client when a message is received. Then on the client append to the message as needed according to the user’s rank. This avoids having to call :UserOwnsGamepass every time a message is sent.
I amended a version for you, @FizzyColas I would suggest following this one instead because of the benefits.
Make a LocalScript in StarterPlayerScripts and paste this inside:
--//Services
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
--//Tables
local developerIds = {
295954212,
84694314,
84398600,
1655354023
}
--//Functions
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
local props = Instance.new("TextChatMessageProperties")
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if table.find(developerIds, player.UserId) then
props.PrefixText = "<font color='#e5d415'>[🔨] [Developer]</font> ".. message.PrefixText
end
if player:GetAttribute("VIP") then
props.PrefixText = "<font color='#d4af37'>[👑] [VIP]</font> ".. message.PrefixText
end
end
return props
end
Add a new script into ServerScriptService and paste this inside:
--//Services
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
--//Controls
local vipGamepassId = 25949990
--//Functions
Players.PlayerAdded:Connect(function(player)
player:SetAttribute("VIP", MarketplaceService:UserOwnsGamePassAsync(player.UserId, vipGamepassId))
end)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamepassId, wasPurchased)
if not wasPurchased or gamepassId ~= vipGamepassId then
return
end
player:SetAttribute("VIP", true)
end)
It should work now, if there are any errors, please tell me and I will fix it.