There are two questions to ask.
--Script in ServerscriptService
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 0000000 -- Change this to your game pass ID
local function onPlayerAdded(player)
local hasPass = false
-- Check if the player already owns the game pass
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
print(player.Name .. " owns the game pass with ID " .. gamePassID)
-- Assign this player the ability or bonus related to the game pass
game.StarterGui.RUN.TextButton.Visible = true
end
end
-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerAdded:Connect(onPlayerAdded)
This script is for the "run" gamepass. This script is for outside purchases(or purchased before/ingame)
Does this script makes the button visible to all other players with people who didn't buy the gamepass?
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 5923482 -- Change this to your game pass ID
local function onPlayerAdded(player)
local hasPass = false
-- Check if the player already owns the game pass
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
print(player.Name .. " owns the game pass with ID " .. gamePassID)
-- Assign this player the ability or bonus related to the game pass
local GUI = player:WaitForChild("PlayerGui")
local RUN = GUI:WaitForChild("RUN")
local button = RUN:WaitForChild("TextButton")
button.Visible = true
end
end
-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerAdded:Connect(onPlayerAdded)
--If I use this code, Output says:
14:53:57.663 - Infinite yield possible on 'Players.S_H1234.PlayerGui:WaitForChild("RUN")'
There is ScreenGUI "RUN" in S_H1234.PlayerGui, but why will it say Infinite yield?
This script is from Official Roblox Developer Forum : Click ME
