Need Script Example

Hello!

I’m Creating a game and I don’t know how to write right script.

I wondered how to create a script connect to the gamepass (adding an item after and text of the picture)

An example of how it should work:
the player bought a gamepass and in the game he should have an item in his inventory and near the nickname there should be a photo from this gamepass.

You can simply link the photo to the ID, but I don’t know how to write a script to connect the game pass with the game.

I know it stupid to read but I really don’t know😶

You can use marketplaceService:GetProductInfo() to return info regarding your gamepass, including its icon.

local function getGamePassImage(ID)
local gamepassInfo;
pcall(function() gamepassInfo = game:GetService("MarketplaceService"):GetProductInfo(ID, Enum.InfoType.GamePass

if gamepassInfo then
return "rbxassetid://"..gamepassInfo.IconImageAssetId
else
warn("Something went wrong fetching info for gamepass["..ID.."]")
end
end
1 Like

Well i think you want a Script that checks if Player owns the gamepass then it rewards them with the tool/item related to that gamepass and in addition you want to show a photo of gamepass somewhere?
Assuming by items you meant Roblox tools you can use the following script it will grant players 1 tool per gamepass they own and you can add multiple gamepass ids in the table
don’t forget to create a folder with name “FolderHoldingGamePassTools” inside ServerStorage and save all the tools related to gamepasses in it

local MarketplaceService = game:GetService("MarketplaceService")
local ServerStorageService = game:GetService("ServerStorage")
local PlayersService = game:GetService("Players")

local FolderHoldingGamePassTools = ServerStorageService:WaitForChild("FolderHoldingGamePassTools")

local GamePassTable = {
	--[[ Format::
			[gamepass id] = address of tool you want to give in case player owns the gamepass;
	]]
	[11509035] = FolderHoldingGamePassTools:WaitForChild("Flame Katana");
}

local function GiveTargetPlayerGamePassTools(TargetPlayer, CurrentBackpack)
	local TargetPlayerUserId = TargetPlayer.UserId
	for GamePassID, GamePassTool in next, GamePassTable do
		if MarketplaceService:UserOwnsGamePassAsync(TargetPlayerUserId --[[player userid]], GamePassID --[[gamepass id]]) == true then
			GamePassTool:Clone().Parent = CurrentBackpack
		end
	end
end

local function OnPlayerAddedEvent(Player)
	Player.ChildAdded:Connect(function(Child)
		if Child:IsA("Backpack") == true then
			GiveTargetPlayerGamePassTools(Player, Child)
		end
	end)
	local CurrentBackpack = Player:FindFirstChildOfClass("Backpack")
	if CurrentBackpack ~= nil then
		GiveTargetPlayerGamePassTools(Player, CurrentBackpack)
	end
end

PlayersService.PlayerAdded:Connect(OnPlayerAddedEvent)
for _, Player in next, PlayersService:GetPlayers() do
	task.spawn(OnPlayerAddedEvent, Player)
end

Now for showing the picture of gamepass part i suggest that you try to read and understand the script i gave you above then apply it to your localscript that will check if player owns the gamepass and show its icon to the player

1 Like