Updating UI If User Owns Badge

Yeah, they get the badge in my game.

Whenever you give out the badge you can just make the button visible from there.

--when player joins the game
if BadgeService:UserHasBadgeAsync(userId, badgeId) then
        button.Visible = true
end
--when the player is given the badge
BadgeService:AwardBadge(userId, badgeId)
button.Visible = true

Obv you have to set button equal to where the button actually is, for example:
Player.PlayerGui.ScreenGui.Button

Yeah I’ve already done that. The issue is, is that the ui updates once the player resets or rejoins the game.

Send a remote event to the client to update it

If you do both of the code he gave, it should work. You could turn off the setting that makes that UI reset on death if you would like. But what he gave should work.

Change the ResetOnSpawn property of the ScreenGui to false, so it doesn’t reset when the player respawns.

About it not working when the player joins, --when player joins the game if BadgeService:UserHasBadgeAsync(userId, badgeId) then button.Visible = true end
this should always work if the player owns the badge.

Perfect it works now. One last thing, I have it set so when you click the visible button you get +10 of a currency. How would I make it so that the button doesn’t re-appear visible anymore after clicking the button and claiming the +10 currency?

Now that the button appears on join, how would I remove this button when its clicked so that it doesn’t reappear again?

When the button is clicked and after giving the 10 currency do - button:Destroy()

This is one of mine. Notice how it makes some text visible … that is in the UI.
I’m sure this can be modified to your needs. (I place it in ServerScriptService)

local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassID = 11389887 -- BlueGmePass -- Sport Drink & Soda Drink

function Spawned(player)
	wait(1.1) local HasGamepass = false
	local success, message = pcall(function()
		HasGamepass = MarketPlaceService:UserOwnsGamePassAsync(player.userId, gamepassID)
	end)
	
	if not success then
		warn("Checking Gamepass "..tostring(message))
		return
	end
	
	if HasGamepass == true then	-- print("Adding BlueGamePass")
		game.ServerStorage.Tools.SpeedDrink2:Clone().Parent = player.Backpack
		player.PlayerGui.ShopGui.Frame.Frame_1.Gamepass1.TextLabel.Visible = true
		player.PlayerGui.ShopGui.Frame.Frame_1.Gamepass1.Own.Value = true
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		Spawned(player)
	end)
end)

Doesn’t seem to destroy the button when re-joining the game.

I will actually be using this for my gamepasses, thanks alot.

You have to use a DataStore to detect that they already claimed it.

Is there a way I could possibly make it so that the button is visible but not clickable anymore?

Looking at it now 2 years latter it looks a bit sloppy :rofl: You may want to touch it up a bit.
I have surly learned a lot in 2 years. But, that script has never failed me …

1 Like

set the Active property to false;

button.Active = false

Doesn’t seem to work. Still lets me keep clicking and gaining +10 everytime.

Sorry, try this :

local clickedConn;
clickedConn = button.Activated:Connect(function() 
    clickedConn = clickedConn:Disconnect() and nil
    --whatever else you need to do when the player clicks the button
end)

^this would only work on client
if you are connecting to MouseButton1Click then you would use this:

local clickedConn;
clickedConn = button.MouseButton1Click:Connect(function() 
    clickedConn = clickedConn:Disconnect() and nil
    --whatever else you need to do when the player clicks the button
end)

Yeah this worked thanks. How would I do the datastore thing?

It isn’t the easiest thing to explain through the devforum so, I would refer to another reply I made a while back. Anyway to detect if is the first time a person joins the game? - #5 by keith_220 Just change the firstTime joined variable to whether or not they claimed the currency or not. And when they do claim the currency set the datastore to true (or what i do in the example set it to 1). I would highly suggest watching the video on datastores that I linked to that reply.

Oh I see, thanks for the help!

1 Like