I need help with a broken script

so people dont understand currently, i just want my code rearranged so it can fit the “local response” into the area near the note in the code that says “I want the local I talked about before around here.”, so basically inside the “while true do” area.

  1. Currently my game is about to reach 100k visits, and I want to set a event for my players. So I’m adding a live visit count to my game using “HTTPService”.

  2. So, it works a tiny bit, but the code only gets the HTTP request once because the codes all messed up, so it cannot update.

  3. Unfortunately, I’m a rookie at coding, so I don’t know how to rearrange this code so when it updates, it updates the HTML from the HTTP. Can someone nice rearrange this?

Heres the code for research.

local suffixes = {'','K','M','B'}

local function format(val)
	for i=1, #suffixes do
		if tonumber(val) < 10^(i*3) then
			return math.floor(val/((10^((i-1)*3))/100))/(100)..suffixes[i]
		end
	end
end

-- Setup --

local GoalCode = "GG!" 

local CodeText =  "New Code: " .. GoalCode

local PercentCap = "100%"

local Goal = 100000

local ProgressCap = Goal

local BarProgress = 0

local CooldownRef = 10 

local UpdateText = "Updating" 

local Unlocked = "🏆 Completed 🏆" 

local Locked = "🔒 Locked 🔒" 

local TweenService = game:GetService("TweenService")

-- Get Request --

local HttpService = game:GetService("HttpService");

local Response = HttpService:RequestAsync({

	Method = "GET"; -- Type Method

	Url = string.format("https://games.rprxy.xyz/v1/games?universeIds=%d", game.GameId);

}); -- this whole local is what I need replaced somewhere OOOOOOOOOOOOOOOOOOOOOOOOOO

-- SYSTEM --

if (Response.Success and Response.Body) then

	local Body = HttpService:JSONDecode(Response.Body)

	local Visits = Body.data[1].visits;

	while true do

		wait(math.random(2,3))

        -- I want the local I talked about before around here.

		local Percent = Visits / Goal * 100

		script.Parent.Progress.Text = Percent .. "% " .. "( " .. (format(Visits)) .. " / " .. (format(Goal)) .. " )"

		script.Parent.Bar.Size = UDim2.new(Visits * 0.001,0,1,0) 

		script.Parent.Parent.TextLabel.Text = "Goal: "..(format(Goal)).." Visits"

		if Visits >= Goal or Visits == Goal or Percent > 100 then

			script.Parent.Bar.Size = UDim2.new(1,0,1,0)

			script.Parent.Progress.Text = PercentCap .. "( " .. (format(ProgressCap)) .. " / " .. (format(Goal)) .. " )"

			script.Parent.Parent.CodeText.Text = CodeText

			wait(1)

			script.Parent.Progress.Text = Unlocked

		else

			script.Parent.Parent.CodeText.Text = Locked

		end

		wait(CooldownRef) 

		script.Parent.Progress.Text = UpdateText
		script.Parent.Parent.CodeText.Text = UpdateText

	end
end

And yes, when I said I was a rookie, the script was a free model, I just want it rearranged.

What is the problem? I am not sure entirely why you need this. Also rprxy is kinda unstable and I wouldn’t trust it for a main game event/mechanic. If you want to time a event the same for every server than you can use tick() to get a global number that is the seconds(down to the millisecond) since Jan 1st 1970. Then plan forward for when tick() equal a certain number in the future and let code run then.

1 Like

I dont understand why i would need to Tick(). I just need my code rearranged. At least tell me how to use Tick()

Well if your doing a live event and you need it to be timed correctly than tick() will help you.

Try watching this video: How to make a LIVE EVENT - Roblox Tutorial - YouTube

1 Like

Thats very useful, thanks for the link. But its not what im looking for. I need a visit event, not a live time event. What im looking for is to rearrange the “local response”. You can see where I spam some notes in the code. Yes, I know I cant explain well, sorry about that.

local suffixes = {'','K','M','B'}

local function format(val)
	for i=1, #suffixes do
		if tonumber(val) < 10^(i*3) then
			return math.floor(val/((10^((i-1)*3))/100))/(100)..suffixes[i]
		end
	end
end

-- Setup --

local GoalCode = "GG!" 

local CodeText =  "New Code: " .. GoalCode

local PercentCap = "100%"

local Goal = 100000

local ProgressCap = Goal

local BarProgress = 0

local CooldownRef = 10 

local UpdateText = "Updating" 

local Unlocked = "🏆 Completed 🏆" 

local Locked = "🔒 Locked 🔒" 

local TweenService = game:GetService("TweenService")

-- Get Request --

local HttpService = game:GetService("HttpService");

local Response = HttpService:RequestAsync({-- this whole local is what I need replaced somewhere OOOOOOOOOOOOOOOOOOOOOOOOOO

	Method = "GET"; -- Type Method-- this whole local is what I need replaced somewhere OOOOOOOOOOOOOOOOOOOOOOOOOO

	Url = string.format("https://games.rprxy.xyz/v1/games?universeIds=%d", game.GameId);-- this whole local is what I need replaced somewhere OOOOOOOOOOOOOOOOOOOOOOOOOO
-- this whole local is what I need replaced somewhere OOOOOOOOOOOOOOOOOOOOOOOOOO
}); -- this whole local is what I need replaced somewhere OOOOOOOOOOOOOOOOOOOOOOOOOO

-- SYSTEM --

if (Response.Success and Response.Body) then

	local Body = HttpService:JSONDecode(Response.Body)

	local Visits = Body.data[1].visits;

	while true do

		wait(math.random(2,3))

        -- I want the local somewhere around here so it can update
        -- I want the local somewhere around here so it can update
        -- I want the local somewhere around here so it can update
        -- I want the local somewhere around here so it can update
        -- I want the local somewhere around here so it can update
        -- I want the local somewhere around here so it can update

		local Percent = Visits / Goal * 100

		script.Parent.Progress.Text = Percent .. "% " .. "( " .. (format(Visits)) .. " / " .. (format(Goal)) .. " )"

		script.Parent.Bar.Size = UDim2.new(Visits * 0.001,0,1,0) 

		script.Parent.Parent.TextLabel.Text = "Goal: "..(format(Goal)).." Visits"

		if Visits >= Goal or Visits == Goal or Percent > 100 then

			script.Parent.Bar.Size = UDim2.new(1,0,1,0)

			script.Parent.Progress.Text = PercentCap .. "( " .. (format(ProgressCap)) .. " / " .. (format(Goal)) .. " )"

			script.Parent.Parent.CodeText.Text = CodeText

			wait(1)

			script.Parent.Progress.Text = Unlocked

		else

			script.Parent.Parent.CodeText.Text = Locked

		end

		wait(CooldownRef) 

		script.Parent.Progress.Text = UpdateText
		script.Parent.Parent.CodeText.Text = UpdateText

	end
end

I am assuming the problem is that api requires a universe id and not a game id.

You can use game id with this and get the universe id with that.

https://games.roblox.com/v1/games/multiget-place-details?placeIds=GAME_ID_HERE

Its not from from any API, I checked long ago. I want the “local response” from the script to update from http updates instead of having only one update from the http. Dont understand me? its fine, i got some workarounds.

You will need a proxy though to access Roblox API’s.

Thanks, but its not what im looking for. so people dont understand currently, i just want my code rearranged so it can fit the “ local response” into the area near the note in the code that says “I want the local I talked about before around here.”, so basically inside the “while true do” area. i want it inside there so it can loop the HTTP updates without breaking.

I really got no idea about this and/or don’t really got what you mean.

Try switching these:

and this:

Try and make it look like this:

while true do
   wait(math.random(2,3))
   if (Response.Success and Response.Body) then
      --Code
   end
end

Not really sure if that will help but try lol

1 Like

alright. but do i have to copy or take the

if (Response.Success and Response.Body) then

into the told area

Well, looks like it did not work. Thanks for the idea.

1 Like