Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a badge checker with filtering enabled on?

This script has to check every two seconds if a player have the badge, if not the X stays visible. But if they do the X goes away. This script works normaly but in this game I use filtering enabled and made the script localscript version. I tried a normal script but that even didn't work. Now it is Playergui > Gui > frame > frame >... > localscript. But local scripts haven't acces to badge service. And when we do a normal script is it not working because the filtering enabled. We also tried with remote event but still not working.

b = game:GetService("BadgeService")
local player = game.Players.LocalPlayer
while wait (2) do
	if b:UserHasBadge(player.userId, 9999999) then --badge id
	script.Parent.Image = "http://www.roblox.com/asset/?id="
	else
	script.Parent.Image = "http://www.roblox.com/asset/?id=47604833"
	end
end

So my second method:

this is the remote version This script is inside the playergui, frame etc..

wait(2)
while wait (2) do
	if game.Workspace.BadgeMothers.BadgeHad01:FireServer() then
	script.Parent.Image = "http://www.roblox.com/asset/?id="
	else
	script.Parent.Image = "http://www.roblox.com/asset/?id=47604833"
	end
end

and this script its the event script inside the ServerScriptStorage:

local event = Instance.new("RemoteEvent") 
event.Parent = game.Workspace.BadgeMothers
event.Name = "BadgeHad01"
event.OnServerEvent:connect(function(player)
local b = game:GetService("BadgeService")
b:UserHasBadge(player.userId, 99999999)
end)

thank you

2 comments

0

Why do you need to check every two seconds? When you give out the badge just fire a remote to update the client?

0

Its for a badge list wait I will put the remote version here too

1 answer

You are using a remote event to but you cannot return a value within the call process so for this task it is best to use a remote function.

I do not see any reason that you would need to request this information every two second, you should fire the client when you add a badge ect. Lastly it is a very good idea to cache the results as they should not change.

Here is a quick example ( server script):-

-- store the badges in
local badgeList = {}

-- create remote
local rem = Instance.new('RemoteFunction', game:GetService('ReplicatedStorage'))
rem.Name = 'badgeChack'

-- the badges check list
local badgeList = {
	1111, 2222, 333
}

local bageServ = game:GetService('BadgeService')

-- adds found badges to the list
local function hasBadges(plrUsrId)
	local tmpTable = {}
	table.insert(tmpTable, 'test') -- just for testing
	table.insert(tmpTable, 1234) -- just for testing
	for _, v in pairs(badgeList) do
		if bageServ:UserHasBadge(plrUsrId, v) then table.insert(tmpTable, v) end
	end
	return tmpTable
end

-- adds the players badges that are found
local plrs = game:GetService('Players')
plrs.PlayerAdded:connect(function(plr)
	badgeList[plr.UserId] = hasBadges(plr.UserId)
end)

-- clers the saved bages list
plrs.PlayerRemoving:connect(function(plr)
	badgeList[plr.UserId] = nil
end)

-- return a list of bages the user currently has
function rem.OnServerInvoke(plr)
	return badgeList[plr.UserId]
end

Local script:-

local rem = game:GetService('ReplicatedStorage'):WaitForChild('badgeChack')

script.Parent.MouseButton1Click:connect(function()
	print(unpack(rem:InvokeServer()))
end)

You will be able to easily add, edit and delete from the cached badge list.

I hope this helps, please comment If you do not understand how/why this script works.

This discussion is preserved as it was. New answers, comments, and votes are closed.