I’ll explain this in full, basically I have a GUI button where if you click it, it keeps checking if you have a badge (so that if you get it while in-game it also keeps checking), if you don’t have the badge it’ll show one of the Frames saying “You need to try again” and will keep checking to see if you owned the badge, if you already own the badge it will show one of the Frames that has a claim UGC text button (so basically if you get the badge while in-game it will keep rechecking and if you do get it, the GUI where you can claim the UGC appears, the UGC is a free limited), so I wanted to add a script to the textbutton when its clicked that basically checks if your name is in the whitelist, and if it is and you own the badge (it already checked if you own the badge, otherwise this GUI wouldn’t have appeared to you in the first place), it will give you the purchase prompt for the free limited UGC.
How can I make this? I already got everything working except for the last part which is the claim ugc textbutton.
This is the whitelist script: (server script under serverscriptservice)
local Whitelist = {
--[[Put userIds here to allow them to claim the UGC.
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)
This is what the GUI looks like: (under startergui)
^ Picture Explained: Basically the “BadgeGUI” Frame is the frame that shows if you own the badge, which has a TextButton to claim the UGC called “ClaimButton”, and the “NotiFrame” is the frame that appears with a notification if you don’t own the badge, and the “MainFrame” is the Frame that has a TextButton which checks whether you have the badge or not everytime you click it, and it either shows the “BadgeGUI” if you own the badge, or it shows the “NotiFrame” if you don’t own the badge.
This is the localscript inside the TextButton that is found inside “MainFrame” that checks if you own the badge:
local BadgeService = game:GetService("BadgeService")
local BadgeID = 0 -- Change to your Badge ID
local Gui = script.Parent.Parent.Parent.BadgeGUI -- Change "Frame" to whatever your frame name is which inside the screengui and will open when the player DOES have the badge
local NotiFrame = script.Parent.Parent.Parent.NotiFrame -- Change "NotiFrame" to whatever your frame name is which inside the screengui which will open if the player doesnt have the badge
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local hasBadge = BadgeService:UserHasBadgeAsync(player.UserId, BadgeID)
if hasBadge then
Gui.Visible = true
else
NotiFrame.Visible = true
wait(5) -- Here you can change how long the NotiFrame is visable for
NotiFrame.Visible = false
end
end)