Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I go about assigning multiple values to this variable?

local ASSET_IDS = 1234567
local BADGE_ID = 2124650145

local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerOwnsAsset = MarketplaceService.PlayerOwnsAsset

Players.PlayerAdded:Connect(function (player)
	local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, player)
	if doesPlayerOwnAsset then
		BadgeService:AwardBadge(player.UserId,BADGE_ID)
	end
end)

Line in regards

local ASSET_IDS = 1234567

1 comment

0

use tables

1 answer

You would want to use tables to store all your IDs...

local ASSET_IDS = {12345, 12345, 12345, 12345}

If you wanted individual badge IDs for each asset you could do...

local ASSET_IDS = {['12345'] = 09876, ['67890'] = 4567}

This would change the contents of your PlayerAdded connection...

Example 1

Players.PlayerAdded:Connect(function(player)
	for index, assetId, in pairs(ASSET_IDS) do
		local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, player, assetId)
		if not success then warn(message) end
		
		if doesPlayerOwnAsset then
			BadgeService:AwardBadge(player.UserId, BADGE_ID)
		end
	end
end)

Example 2

Players.PlayerAdded:Connect(function(player)
	for assetId, badgeId in pairs(ASSET_IDS) do
		local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, player, assetId)
		if not success then warn(message) end
		
		if doesPlayerOwnAsset then
			BadgeService:AwardBadge(player.UserId, badgeId)
		end
	end
end)

1 comment

0

Thank you so much.

This discussion is preserved as it was. New answers, comments, and votes are closed.