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