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.
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.
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.
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.
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.
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)
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.