Server badge checking

Hello!

Recently, I have been trying to make something, that checks if other player has some badges from JToH and make changes on client, depending if player has the badges or not.

More detailed explanation:
Player A joins the server → Player A selects if she/he wants to view her/his badges or if she/he wants to view badges of Player B (the Player B ID, I already made script for ID checking) → Localscript should detect what choice Player A made (local script fires remote event later on)
This is the moment when problems start to occur if the player selected to view Player B badges.

The things I want the server to know: what player fired the server, what badge should it check for and other player ID.**

I have been trying to make multiple remote events for each badge, however after adding some remove events it started to be messy.

Also is there a better method to save Player B ID on server for some time, since I needed to make a number value on the server side in order to check if player has the badge.

I didn’t really know what to do from that point, so I started to make something like this:

Local script:

while true do
wait()
local localplr = game.Players.LocalPlayer
local background = localplr:WaitForChild("PlayerGui"):WaitForChild("Thing"):WaitForChild("Background")
local ring1 = background.Ring1.ScrollingFrame
local userid = background.UserSelect.customuserid

local AnnoyinglySimpleTrials = ring1.AnnoyinglySimpleTrials
local Anger = ring1.Anger
local Neat = ring1.NotEvenATower
local Madness = ring1.Madness
local Killjoys = ring1.Killjoys
local Hecc = ring1.Hecc
local keyboard = ring1.Keyboard
local Stress  = ring1.Stress
local Screen = ring1.Screen
local Rage = ring1.Rage
local Impossible = ring1.Impossible
local Skill = ring1.Skill
local Thanos = ring1.Thanos
local Laptop = ring1.Laptop
local Void = ring1.Void
local Ring1Rush = ring1.Ring1TowerRush
--
while game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Thing"):WaitForChild("Background"):WaitForChild("UserSelect"):WaitForChild("user").Value == 2 do
	wait()
	local tower = 0
	function sendRemote(customid)
		game.ReplicatedStorage.Check:FireServer(customid,localplr)
		wait()
	end
	
	function change(towerID)
		game.ReplicatedStorage.Check.OnClientEvent:Connect(function(Status)
			if tower == 1 then
				if Status == "True" then
					AnnoyinglySimpleTrials.Completed.Visible = true
					AnnoyinglySimpleTrials.NotCompleted.Visible = false
				elseif Status == "False" then
					AnnoyinglySimpleTrials.Completed.Visible = false
					AnnoyinglySimpleTrials.NotCompleted.Visible = true
				end
			elseif tower == 2 then
				if Status == "True" then
					Anger.Completed.Visible = true
					Anger.NotCompleted.Visible = false
				elseif Status == "False" then
					Anger.Completed.Visible = false
					Anger.NotCompleted.Visible = true
				end
			elseif tower == 3 then
				if Status == "True" then
					Neat.Completed.Visible = true
					Neat.NotCompleted.Visible = false
				elseif Status == "False" then
					Neat.Completed.Visible = false
					Neat.NotCompleted.Visible = true
				end
			elseif tower == 4 then
				if Status == "True" then
					Madness.Completed.Visible = true
					Madness.NotCompleted.Visible = false
				elseif Status == "False" then
					Madness.Completed.Visible = false
					Madness.NotCompleted.Visible = true
				end
			end
		end)
	end
	
	--Ring 1 Towers
	for i = 1,4 do
		sendRemote(userid.Value)
		change(tower+1)
		wait()
	end
end
--
end

Server side script:

game.ReplicatedStorage.Check.OnServerEvent:Connect(function(localplr,customid)
	local BadgeService = game:GetService("BadgeService")
	
	local background = localplr:WaitForChild("PlayerGui"):WaitForChild("Thing"):WaitForChild("Background")
	local userid = background.UserSelect.customuserid
	userid.Value = customid
	
	function badgeCheck(TowerBadgeID)
		if BadgeService:UserHasBadgeAsync(userid.Value, TowerBadgeID) then
			game.ReplicatedStorage.Check:FireClient(localplr,"True")
		else
			game.ReplicatedStorage.Check:FireClient(localplr,"False")
		end
	end
	local tower = 0
	local id = game.ServerStorage.TowerBadgeIDs
	local IDTable = require(id)
	local whatid = 0
	
	for i = 1,4 do
		tower = tower + 1
		badgeCheck(IDTable[whatid+1])
		wait()
	end
end)

Module script:

local IDs = {
		[1] = "2124457509";
		[2] = "2124457501";
		[3] = "2124457516";
		[4] = "2124457502";
		--[5] = "2124457515";
	}

return IDs

Can you please help me with this issue? Thanks.

So you could use a server script to check when a player joins, they have their badges checked,

local amountBadges = 5
local BadgeService = game:GetService("BadgeService")
local badgeTable = require(game.Workspace.Module) --change this
game.Players.PlayerAdded:Connect(function(player)
   local hasBadge = {}
   for index = amountBadges,1, -1 do 
      -- check if player has badge
      If BadgeService:UserHasBadgeAsync(player.UserId, badgeTable[index]) then
         hasBadge[index] = true
      end
   end
   game.ReplicatedStorage.Events.TowerCheck:FireClient(player,hasBadge)
end)

Then you would need to send this information to the client which you can use remotes. The client can then process the information according to the values sent

--client side
game.ReplicatedStorage.Events.TowerCheck.OnClientEvent:Connect(function(badges)
   for tower, value in pairs(badges) do
      if value == true then 
         towers[tower].Value = true
      else
         towers[tower].Value = false
      end
   end
End) 

I think you can edit the scripts to suit your needs
Sorry if something is incorrect I am typing on my phone.

2 Likes

Thanks for responding, however what if Player A wanted to check if Player B has the badges and the Player B wouldn’t be on the server.
Also badges of the player that joins are already checked by local script.