Infinite Yield possible on 'Players'ArchieStatxx.PlayerGui.CarSpawner.Selector.ScrollingFrame:WaitForChild("BMW 530")

Hi all!

I have done a car dealership and when you FireServer() the buy function, when it is making an attempt to change something in the Players UI it returns an Infinite Yield yet what it is looking for is there.

This is the error:

Infinite Yield possible on 'Players’ArchieStatxx.PlayerGui.CarSpawner.Selector.ScrollingFrame:WaitForChild(“BMW 530”)

events.Remotes:WaitForChild("buyCar").OnServerEvent:Connect(function(plr, veh, plrMoney, vehicle)
	local GUI = player.PlayerGui:WaitForChild("CarSpawner"):WaitForChild("Selector")


	if plrMoney >= veh[2] then
		player.PlayerStats:WaitForChild("Bank").Value = plrMoney - veh[2]
		GUI:WaitForChild("ScrollingFrame"):WaitForChild(vehicle).PurchaseButton.Visible = false 

	
	end



end)

infinite yield possible indicates that the object doesn’t exist

  1. try verifying the object exists
  2. try verifying if the server can see the object (since you’re using a serverscript)

Probably because the gui object named BMW 530 doesn’t exist.

Well, as the others have said, make sure the server can see the object and that it even exists. But, I want to point out another thing.

You have the client send you the amount of money they have, and the amount the vehicle costs. For one, the player can very much give themselves an infinite amount of cash through this. Instead, have the prices saved on the server as a table ex:

local prices = {
	["BMW 530"] = 100
}

And also record the player’s money on the server.

local prices = {
	["BMW 530"] = 100
}

events.Remotes:WaitForChild("buyCar").OnServerEvent:Connect(function(plr, vehicle)
	local GUI = plr.PlayerGui:WaitForChild("CarSpawner"):WaitForChild("Selector")
	local plrMoney = plr.PlayerStats:WaitForChild("Bank")
	local price = prices[vehicle]

	if price and plrMoney.Value >= price then
		plrMoney.Value -= price
		GUI:WaitForChild("ScrollingFrame"):WaitForChild(vehicle).PurchaseButton.Visible = false 
	end
end)

Also, here’s an example of what the client could do to give themselves infinite money through the current setup (how you had it).

events.Remotes:WaitForChild("buyCar"):FireServer({[1] = nil, [2] = 0}, math.huge(), "BMW 530")

The server seems to not have it, it is in the players ui’s though
image

To fix what i said before when I check it with Current: Server, it is not seeing it inside of the player either.

that means the GUI is probably being created in a localscript,

there are a couple options to fix this

  1. create the GUI before the game even starts but only enable it when the time is needed
  2. create the GUI with the server and place it in the player’s playergui folder

also, they could buy virtually any vehicle they want for free by just changing the veh[2] value to 0.

The local script currently duplicates all inside of a table what the car name and the price so how would I go about doing ot via the server instead

Yes, but the buying any vehicle isn’t nearly as important as being able to get any amount of money you want.

by doing what I showed in my last post.

Am I adding the vehicle param back in?

Oh, yes, change the plrMoney to vehicle in the onserverevent parameters, I forgot to change that.

Wouldn’t I keep the plrMoney as it is being used or are you saying swap them around?

I declared the plrMoney variable later in the onServerEvent.

The cash of the player is remaining the same?

I subtracted it by the price of the vehicle.

It is not subtracting anything from the value

It does though. Unless the client isn’t updating the current value of the object or the script is erroring somewhere before subtracting the price, it will subtract it.

Its not erroring anywhere, its just not subtracting it