Need help making this script work? (urgent)

So basically I have a normal badge award function in multiple scripts, each script will basically work by awarding a different badge which would give a different UGC purchase prompt to the player receiving the badge to get a different free UGC limited. (each script will award a different ugc)

I have the badge award script:

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		game:GetService("BadgeService"):AwardBadge(player.UserId, 000000) --Replace the numbers with your badge asset ID (example: 1234567890)
	end
end)

And I have this whitelist script that has names of people, and those people ONLY should be able to get the UGC purchase prompt, if the person’s name isn’t in the whitelist he would ONLY get the badge, NOT the UGC purchase prompt: (a server script under serverscriptservice)

local Whitelist = {
    --[[Put userIds here to allow them to be awarded the UGC in the game.
    Or, you could use their roblox name (not case sensitive) instead if you'd like
    ]]
	"Roblox", -- Player Name Example.
	"Builderman",
}

for i, user in Whitelist do
	Whitelist[i] = string.lower(user)
end

game.Players.PlayerAdded:Connect(function(player)
	if table.find(Whitelist,player.UserId) == nil and table.find(Whitelist,string.lower(player.Name)) == nil then
		player:Kick("I do not recognize you...")
	end
end)

And I wanna add a UGC prompt purchase inside the first badge award function/script that I mentioned at the start but I am not sure how.

How can I make all of this so that it works? And how do I ensure 100% exploiters can’t somehow bypass and steal all the UGC stock?

1 Like

For starters, I would recommend having a singular script handling badge and UGC prompts, such as the script which has your player whitelist. In terms of awarding badges, you should create a new Bindable Event inside of Server Storage which is hooked up to communicate between each badge awarding script and the main script (as mentioned). I should also note that you would want to have the player, badge ID, and UGC ID as arguments when sending the call to the main script.

Since anyone is able to claim the badge, not much else is needed to be done other than to award the badge after receiving a call from the Bindable Event. As for rewarding UGC stock to the whitelisted players, you can include a check after the badge was awarded to decide if the player sent is on the whitelist, and if so, award them the UGC (which you have already displayed partly on the second script provided). You will not have to worry about exploiters taking advantage and taking all of the UGC’s stock, as the player is checked over and as long as the exploiter is not present in the whitelist, they will not receive the prompt to purchase the UGC. Furthermore, by storing the Bindable Event inside of Server Storage, the exploiter will not be able to fire it from their client. However, assuming that players can be added to the whitelist, there is not much that can be done if an exploiter manages to get onto the whitelist, in which case the best option you have is to create your own anti-cheat.

Awarding UGC is the same as prompting the player with any other purchase using :PromptPurchase().

1 Like

Would you mind helping me go on with this step by step? Apologies but I am a super beginner scripter and I wouldn’t have asked for help if it wasn’t a time-urgent script that I needed. :sad:

No problem!

  1. To begin, you would need to create a new Bindable Event inside of ServerStorage, give it a name that makes sense, such as AwardBadge (I will be using that name to refer to the Bindable Event)
  2. Within your badge award scripts, replace :AwardBadge() with the firing of the Bindable Event
local ServerStorage = game:GetService("ServerStorage")
local awardBadgeEvent = ServerStorage:FindFirstChild("AwardBadge") -- Bindable Event

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") and event then -- Ensure bindable event exists
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		awardBadgeEvent:Fire(player, 0000, 0000) -- Player, Badge ID, UGC ID
	end
end)
  1. Receive the call from the Bindable Event from within your main script, such as your whitelist script
local ServerStorage = game:GetService("ServerStorage")
local BadgeService = game:GetService("BadgeService")

local awardBadgeEvent = ServerStorage:FindFirstChild("AwardBadge") -- Bindable Event

local Whitelist = {
	"Roblox",
	"Builderman"
}

for i, user in Whitelist do
	Whitelist[i] = string.lower(user)
end

awardBadgeEvent.Event:Connect(function(player, badgeID, ugcID)
    -- Received the call from the bindable event
end)
  1. Award badges and award UGCs after receiving the call from the Bindable Event
local ServerStorage = game:GetService("ServerStorage")
local BadgeService = game:GetService("BadgeService")
local MarketplaceService = game:GetService("MarketplaceService")

local awardBadgeEvent = ServerStorage:FindFirstChild("AwardBadge") -- Bindable Event

local Whitelist = {
	"Roblox",
	"Builderman"
}

for i, user in Whitelist do
	Whitelist[i] = string.lower(user)
end

awardBadgeEvent.Event:Connect(function(player, badgeID, ugcID)
    -- Award the badge to every single player
    BadgeService:AwardBadge(player.UserId, badgeID)

    if table.find(Whitelist, player.UserId) == true or table.find(Whitelist, string.lower(player.Name)) == true then
        -- Award the UGC to whitelisted players
        MarketplaceService:PromptPurchase(player, ugcID)
    end
end)

Hopefully this has helped to break down my response into steps that you can take to implement it into your game, if something is not clear feel free to let me know so I can explain it!

1 Like