Help on making a gamepass script?

Hi.
How would i make this into a gamepass owners only script:

local gamepassId = 24739477 -- Gamepass ID
local service = game:GetService("MarketplaceService")

local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')

local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

ChatService.SpeakerAdded:Connect(function(PlayerName)
	local Speaker = ChatService:GetSpeaker(PlayerName)
	if (Players[PlayerName].UserId == 902603595) then
		Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
		Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
		Speaker:SetExtraData('Tags', {{TagText = 'Donator 😎', TagColor = Color3.fromRGB(255, 0, 0)}})
	end
end)

What does “gamepass owners only script” mean? Could you maybe re-word it so I could understand the issue and help?

Oh, i mean make it so gamepass owners have the chat tag while non gamepass owners do not. Sorry for the poor wording

You can use MarketplaceService's :UserOwnsGamePassAsync(Players[PlayerName].UserId,gamepassId) to check if the player has the gamepass.

So

if (MarketplaceService:UserOwnsGamePassAsync(Players[PlayerName].UserId,gamepassId)) then
-- your code
end
local gamepassId = 24739477 -- Gamepass ID
local service = game:GetService("MarketplaceService")

local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')

local ChatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

ChatService.SpeakerAdded:Connect(function(PlayerName)
	local Speaker = ChatService:GetSpeaker(PlayerName)
    local hasPass = false
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)

	if not success then
		warn("Failed to check if player has gamepass")
		return
	end
 
	if hasPass == true or Players[PlayerName].UserId == 902603595 then
		Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
		Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
		Speaker:SetExtraData('Tags', {{TagText = 'Donator 😎', TagColor = Color3.fromRGB(255, 0, 0)}})
	end
end)

Im pretty sure this will work, its from the Game Passes devforum page. Make sure to always look around before making a forum post

This wouldn’t work because the “player” instance hasn’t been defined, instead use:

local gamepassId = 24739477 -- Gamepass ID
local Players = game:GetService('Players')
local SSService = game:GetService('ServerScriptService')
local MPService = game:GetService("MarketplaceService")
local ChatService = require(SSService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))

ChatService.SpeakerAdded:Connect(function(PlayerName)
	local player = Players:FindFirstChild(PlayerName)
	local hasPass
	if player then
		hasPass = MPService:UserOwnsGamePassAsync(player.UserId, gamepassId)
	end
	local Speaker = ChatService:GetSpeaker(PlayerName)
	if hasPass or player.UserId == 902603595 then
		Speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
		Speaker:SetExtraData('ChatColor', Color3.fromRGB(255, 255, 255))
		Speaker:SetExtraData('Tags', {{TagText = 'Donator 😎', TagColor = Color3.fromRGB(255, 0, 0)}})
	end
end)