I need help with a gui script

Hello, I would like some help basically I’m working on a game like find the markers and I would like it to do the same thing that when you touch a marker it shows a gui but when you touch it again it doesn’t show it but for me it would be clicking it so the only problem I got is making it that when you click it the first time it shows the GUI only for that player and when you click it again it doesn’t show a gui.

Any help is appreciated.

2 Likes

So you want to show a UI when you click a part?

1 Like

So if you want to make a UI visible with a script, do the following

  1. Make a StarterGui with a ScreenGui and e.g. a frame
  2. Insert a part into workspace and insert a ClickDetector and a script
  3. Insert the following script:

I hope this will help you!

1 Like

That did help me alot but how would I make it that when you click the block again the GUI doesn’t show like after you got the badge and you click it again the GUI doesn’t show.

Uhm

Type script:Destroy() on line 5

You can delete ClickDetector after Click!

The problem on this is that if you join the game again, you can click the gui again. For this you have to add a function (add a script into serverscriptservice). Because you got awarded a badge u can use the UserGotBadgeAsync function to check if the player got the badge. If he got the badge, you just simply destroy the part.

1 Like

What happen if he not going to give Badge?
Then he need DataStoreService

Can you explain a bit further? He said in his second post, that after you got the badge it should not appear again…

Oh that’s my mistake. sorry lol

LocalScript:

local BadgeService = game:GetService("BadgeService")
local BadgeId = 0 -- replace with badge ID
script.Parent.ClickDetector.MouseClick:Connect(function(player)
  local hasBadge

  local success, errMsg = pcall(function()
    hasBadge = BadgeService:UserHasBadgeAsync(game.Players.LocalPlayer.UserId, BadgeId)
 end)
if success and hasBadge ~= true then
 game.ReplicatedStorage.FoundMarker:FireServer(BadgeId) -- Because Badge cannot be awarded in client
end)

ServerScript:

local BadgeService = game:GetService("BadgeService")
game.ReplicatedStorage.FoundMarker.OnServerEvent:Connect(function(player,BadgeId)
 BadgeService:AwardBadge(player.UserId, BadgeId)
end)

Must need RemoteEvent called ‘FoundMarker’ in ReplicatedStorage.

I already got a script that gives the badge all I need is that if they got the badge and they click it again it doesn’t show the GUI and it doesn’t destroy the block cuz it’s 10 per server.

Then you don’t have to award badge in this script?

We can’t detect player own badge if player didn’t join again after Award Badge.
So you have to destroy Click Detector after award.[You Must Destroy Click Detector in LocalScript!] and If player rejoin, Script will find player own badge. Then you can also destroy Click Detector of marker that player owns.

But it will destroy it for everyone on that server I just need it only for that player.

Then Destroy in LocalScript. Maybe work!

You can check if a player owns a badge by using UserHasBadgeAsync().
In your case it would look like this:

A script in serverscriptservice;

game.Players.PlayerAdded:Connect(function(plr)
	
	local success, hasBadge = pcall(function() --/ We use pcall to make sure the script doesn't stop working if there's an error.
		return BadgeService:UserHasBadgeAsync(plr.UserId, badgeID)
	end)
	
	if not success then
		print("error while checking if user owns badge")
		
	end
	
	if hasBadge then
		event:FireClient(plr, badgeID)
	end
	
end)

A localscript inside StarterGui/StarterPlayerScripts

local clickdetector = game.Workspace.ClickDetector

event.OnClientEvent:Connect(function(badgeID)
	
	if badgeID == ur badge id then
		clickdetector:Destroy() --/ Will only destroy for the client because it's inside a localscript.
	end
	
end)
1 Like

Hi!!

If you want to achieve that, as @IamProtectingPeople said, you should use UserHasBadgeAsync() if you want to check if the player got the badge whenever the player joins the game.

to show the gui, make a screengui in the StarterGui and then in your MainScript parent it to the PlayerGui. And then, make it visible with:

ScreenGui.Enabled = true

also, you need to make an If conditional and the UserHasBadgeAsync() method to check if the player got the badge, and if he does, then you fire a remote event to the client and change the MaxActivationDIstance propertie of the ClickDetector to 0.

Hope it helps! :smile: