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)
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)