So that I can provide the gamepass benefits real time so the player will not have to rejoin for the gamepasses to start working?
--Pseudocode
function CheckGamepasses()
if PlayerOwnsGamePass(MyGamePass) then
Player.ChatColor = SpecialChatColor
end
end
CheckGamePasses()
Player.BoughtNewGamepass:Connect(CheckGamePasses)
local MarketplaceService = game:GetService("MarketplaceService")
local ChatServiceRunner = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local Players = game:GetService("Players")
local GamepassID = 0
local SpecialChatColor = Color3.fromRGB(255, 233, 67)
local function gamepassPurchaseFinished(player, gamepassId, wasPurchased)
if wasPurchased and gamepassId == GamepassID then
local speaker = ChatServiceRunner:GetSpeaker(player.Name)
if speaker then
speaker:SetExtraData("ChatColor", SpecialChatColor)
speaker:SetExtraData("NameColor", SpecialChatColor)
end
end
end
function CheckGamepasses(speakerName)
local speaker = ChatServiceRunner:GetSpeaker(speakerName)
local player = speaker:GetPlayer()
if speaker and player then
local success, ownsGamepass = pcall(MarketplaceService.UserOwnsGamePassAsync, MarketplaceService, player.UserId, GamepassID)
if success and ownsGamepass then
speaker:SetExtraData("ChatColor", SpecialChatColor)
speaker:SetExtraData("NameColor", SpecialChatColor)
elseif not success then
warn("An error occurred when checking if the player owns the gamepass")
end
end
end
ChatServiceRunner.SpeakerAdded:Connect(CheckGamepasses)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)