Why doesnt this RemoteEvent fire on line 53?

Tryna make this event fire. Fires when requests table has one value in it. Doesnt fire when 2 or more. Event should fire on line 53
Code:

local httpService = game:GetService("HttpService")
local baseUrl1 = "https://avatar.roblox.com/v1/users/"
local baseUrl2 = "/outfits?itemsPerPage=50"
local requests = {}
local proxyHttp = require(game.ServerScriptService.ProxyRobloxAPI:Clone())
local players = game.Players:GetPlayers()
local v
local targetUserId
local targetUserName
local isRunning = false
local isSendingServer = false
local currentid
local outfitFrame


local function checkPlayer()
	
	if isRunning == false then
		
		print("Running Properly")
		isRunning = true
		isSendingServer = true
	
		if #requests >= 1 then


			local userId = (requests[1])

			local s, x = pcall(function()
				local data = proxyHttp:GetAsync(baseUrl1..userId..baseUrl2) -- https://avatar.roblox.com/v1/users/2046139136/outfits?itemsPerPage=50
				if data then

					print("cleared")
					game.Workspace.Map.Outfits:ClearAllChildren()
					local outfits = data.data 
					for i, v in pairs(outfits) do
						currentid = requests[1]
						local desc = game.Players:GetHumanoidDescriptionFromOutfitId(v.id)
						local thumb = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

						workspace.UserImage.SurfaceGui.ImageLabel.Image = thumb
						local c = game.ServerStorage.BaseAvatar:Clone()
						c.Name = v.name
						c.Parent = workspace.Map.Outfits
						c.HumanoidRootPart.Position = Vector3.new(-123 + (5 * (#workspace.Map.Outfits:GetChildren() - 1)), -5, -59.5)
						c.Humanoid.NameDisplayDistance = 50
						c.Humanoid:ApplyDescription(desc)
						c.HitBox.Position = c.HumanoidRootPart.Position

					end
				end
				table.remove(requests, table.find(requests, currentid))
				game.ReplicatedStorage.RemoveQueue:FireAllClients(requests, targetUserName) --Why doesnt this fire?
				print("table removed")
				wait(1)
				isRunning = false
				isSendingServer =false

			end)
		end



	end
end

local loop = function()
	while true do
		wait(3)

		if #requests == 1 then
			checkPlayer()


		else
			repeat game:GetService("RunService").Heartbeat:Wait() until #requests >= 1
		end
	end
end



game.ReplicatedStorage.RequestUser.OnServerInvoke = function(plr, targetName) -----FIRST THING IN THIS SCRIPT TO HAPPEN
	local s, x = pcall(function()
		targetUserName = targetName
		
		targetUserId = game.Players:GetUserIdFromNameAsync(targetName) --get name id
		workspace.UserImage.SurfaceGui.Enabled = true
		table.insert(requests, targetUserId)
		game.ReplicatedStorage.GetQueue:FireAllClients(requests, targetUserName)
		


		if isRunning == false then
			if #requests == 1 then
				wait()
				checkPlayer()
				print("Put in queue")

			end
		end


	end)
	if not s and x then warn(x) end
end

coroutine.wrap(loop)()

1 Like

I have a theory why it might not work. I might be right. I think that there is an issue with this piece of code inside the checkPlayer function. I added a comment to isRunning = false. You can find it and read a comment added by me.

		if #requests >= 1 then


			local userId = (requests[1])

			local s, x = pcall(function()
				local data = proxyHttp:GetAsync(baseUrl1..userId..baseUrl2) -- https://avatar.roblox.com/v1/users/2046139136/outfits?itemsPerPage=50
				if data then

					print("cleared")
					game.Workspace.Map.Outfits:ClearAllChildren()
					local outfits = data.data 
					for i, v in pairs(outfits) do
						currentid = requests[1]
						local desc = game.Players:GetHumanoidDescriptionFromOutfitId(v.id)
						local thumb = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

						workspace.UserImage.SurfaceGui.ImageLabel.Image = thumb
						local c = game.ServerStorage.BaseAvatar:Clone()
						c.Name = v.name
						c.Parent = workspace.Map.Outfits
						c.HumanoidRootPart.Position = Vector3.new(-123 + (5 * (#workspace.Map.Outfits:GetChildren() - 1)), -5, -59.5)
						c.Humanoid.NameDisplayDistance = 50
						c.Humanoid:ApplyDescription(desc)
						c.HitBox.Position = c.HumanoidRootPart.Position

					end
				end
				table.remove(requests, table.find(requests, currentid))
				game.ReplicatedStorage.RemoveQueue:FireAllClients(requests, targetUserName) --Why doesnt this fire?
				print("table removed")
				wait(1)
				isRunning = false -- isRunning is set to false ONLY if #requests >= 1 is true. Shouldn't it always go back to false (be outside any if statement as one of last lines of this function)?
				isSendingServer =false

			end)
		end

Can you please explain this again? i didnt fully understand. Also why would it affect it? The output is able to print the thing after the event is called.

Major problem is that the IsRunning Variable is being used by everyone you should create a table store if the player is running within it for each player.

Which line is line 53?

2 Likes

Where it fires all clients at the end of the checkplayer() function

Yay your problem got solved by @Extrenious before I finished this replay but there is explanation of what I meant anyway:

Can you please explain this again? i didnt fully understand

This is the function:

local function checkPlayer()

if isRunning == false then

	print("Running Properly")
	isRunning = true
	isSendingServer = true

	if #requests >= 1 then


		local userId = (requests[1])

		local s, x = pcall(function()
			local data = proxyHttp:GetAsync(baseUrl1..userId..baseUrl2) -- https://avatar.roblox.com/v1/users/2046139136/outfits?itemsPerPage=50
			if data then

				print("cleared")
				game.Workspace.Map.Outfits:ClearAllChildren()
				local outfits = data.data 
				for i, v in pairs(outfits) do
					currentid = requests[1]
					local desc = game.Players:GetHumanoidDescriptionFromOutfitId(v.id)
					local thumb = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

					workspace.UserImage.SurfaceGui.ImageLabel.Image = thumb
					local c = game.ServerStorage.BaseAvatar:Clone()
					c.Name = v.name
					c.Parent = workspace.Map.Outfits
					c.HumanoidRootPart.Position = Vector3.new(-123 + (5 * (#workspace.Map.Outfits:GetChildren() - 1)), -5, -59.5)
					c.Humanoid.NameDisplayDistance = 50
					c.Humanoid:ApplyDescription(desc)
					c.HitBox.Position = c.HumanoidRootPart.Position

				end
			end
			table.remove(requests, table.find(requests, currentid))
			game.ReplicatedStorage.RemoveQueue:FireAllClients(requests, targetUserName) --Why doesnt this fire?
			print("table removed")
			wait(1)
			isRunning = false
			isSendingServer =false

		end)
	end



end

end

Simpler version of this function to make it easier to explain:

local function checkPlayer()
	if isRunning == false then
		isRunning = true
		-- Do some stuff
		if #requests >= 1 then
			local s, x = pcall(function()
				-- Do some stuff
				wait(1)
				isRunning = false
				isSendingServer = false
			end)
		end
	end
end
  1. If isRunning is false then the function sets this variable to true
  2. isRunning is set back to false only if #requests >= 1 is true
  3. The only way to run the code inside if isRunning == false block more than once is to set isRunning back to false. It can’t be always done because the only piece of code setting it back to false is in the if #requests >= 1 block.
  4. Try to understand (analyze normal or simpler version of this function step by step) what happens when this function runs when isRunning is equal to false and #requests >= 1 is false.
  5. The answer: isRunning can be never be equal to false again because there is nothing what can set it back to false (even if #requests >= 1 because it’s in if isRunning == false block and isRunning is true)