I figured out a way to make a limited stock work with badges, however this happens

So I made this stock thingy where depending on how many people have the badge, the stock will go down, higher = down, lower = up. Then, after the check wait is ended, it gives these two errors:

  argument #1 expects a string, but table was passed  -  Server - Script:11
  Stack Begin  -  Studio
  Script 'ServerScriptService.Script', Line 11  -  Studio - Script:11
  Stack End  -  Studio
  ServerScriptService.Script:12: attempt to index nil with 'awardedCount'  -  Server - Script:12
  Stack Begin  -  Studio
  Script 'ServerScriptService.Script', Line 12  -  Studio - Script:12
  Stack End  -  Studio

After those errors appear, it doesn’t show the badge count again and the while true do just stops completely. Is there a solution to this?

My script:

local badgeservice = game:GetService("BadgeService")
local text = workspace.Part.BillboardGui.TextLabel
local maxstock = 3000000
local check = 25
local http = game:GetService("HttpService")
local data = http:GetAsync("https://badges.roproxy.com/v1/badges/1597063654359516")


while true do
	if data then
		data = http:JSONDecode(data)
		local stock : number = data.statistics.awardedCount
		local actualstock = maxstock - stock
		text.Text = "STOCK: "..actualstock.."/"..maxstock
		if data.statistics.awardedCount == maxstock then
			text.Text = "Stock Ended!"
		end
	end
	task.wait(check)
end

does this fix your issue?

(you can remove the tostring my bad for leaving that in >_<)

The errors are gone, but the badge count isn’t updating, its just staying the same badge count.

you have to call the data = http:GetAsync(arg) after if data then … end (here)

do you need me to send an example aswell or is that explained clearly enough?

1 Like

yes, i would like an example. |||||||||||||||||||||||

1 Like


There you go that should fix your issue!

1 Like

it still doesn’t work, heres my script with everything that you had, is there something wrong?

local badgeservice = game:GetService("BadgeService")
local text = workspace.Part.BillboardGui.TextLabel
local maxstock = 3000000
local check = 1
local http = game:GetService("HttpService")
local data = http:GetAsync("https://badges.roproxy.com/v1/badges/1597063654359516")

while true do
	if data then
		if typeof(data) == "string" then
			data = http:JSONDecode(data)
		end
		local stock : number = data.statistics.awardedCount
		local actualstock = maxstock - stock
		text.Text = "STOCK: "..actualstock.."/"..maxstock
		if data.statistics.awardedCount == maxstock then
			text.Text = "Stock Ended!"
		end
	end
	data = http:GetAsync("https://badges.roproxy.com/v1/badges/1597063654359516")
	task.wait(check)
end
while true do
	if data then
		if typeof(data) == "string" then
			data = http:JSONDecode(tostring(data))
		end

		local stock : number = data.statistics.awardedCount
		local actualstock = maxstock - stock
		text.Text = "STOCK: "..actualstock.."/"..maxstock
		if data.statistics.awardedCount >= maxstock then
			text.Text = "Stock Ended!"
		end
	end
	data = http:GetAsync("https://badges.roproxy.com/v1/badges/1597063654359516")
	task.wait(check)
end

here is mine which worked for me

1 Like

The variable needs to be inside the while true do, not outside. Thanks for your help! I just had to play around with the script in order to achieve this updating thing.

local badgeservice = game:GetService("BadgeService")
local text = workspace.Part.BillboardGui.TextLabel
local maxstock = 3000000
local check = 1
local http = game:GetService("HttpService")

while true do
	local data = http:GetAsync("https://badges.roproxy.com/v1/badges/1597063654359516")
	if data then
		if typeof(data) == "string" then
			data = http:JSONDecode(tostring(data))
		end

		local stock : number = data.statistics.awardedCount
		local actualstock = maxstock - stock
		text.Text = "STOCK: "..actualstock.."/"..maxstock
		if data.statistics.awardedCount >= maxstock then
			text.Text = "Stock Ended!"
		end
	end
	data = http:GetAsync("https://badges.roproxy.com/v1/badges/1597063654359516")
	task.wait(check)
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.