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

try this:

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
		print(plrMoney.Value, plrMoney.Value - price, price)
		plrMoney.Value -= price
		GUI:WaitForChild("ScrollingFrame"):WaitForChild(vehicle).PurchaseButton.Visible = false 
	end
end)

it should print the amount of money the player has, the amount it will be after subtracting, and the price of the vehicle.

nope its not printing anything

Then that means that it isn’t going through the condition.

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
		print(plrMoney.Value, plrMoney.Value - price, price)
		plrMoney.Value -= price
		GUI:WaitForChild("ScrollingFrame"):WaitForChild(vehicle).PurchaseButton.Visible = false 
	else
		print(price, plrMoney.Value >= price)
	end
end)

Also, make sure that whatever vehicle you are selecting is inside of the price table, otherwise it will come up with the price being nil.

ServerScriptService.CarDealership:24: attempt to compare nil <= number

I just edited the post about that.

It appears that whatever vehicle you are trying to buy is not within the price table. Also, did you change what the client sends to the server? It could be either one of those problems.

As soon as I removed the UI part it started working

Just to be clear, you are saying that you removed this part?

Yeah, that is the line I removed from the code.

That confuses me. There shouldn’t be a problem with the first line, but the

GUI:WaitForChild("ScrollingFrame"):WaitForChild(vehicle).PurchaseButton.Visible = false

I could understand causing problems as it was erroring in the first place. Could you show me what the client is sending to the server?

There is nothing in the scrolling frame on the server

I’m assuming that the client creates all of the buttons inside of the scrolling frame, so just make a remote event to have the client handle that part.

no point of money when you can accomplish everything in the game without it :person_shrugging:

This is just vehicles we are talking about, I’m assuming there is more to the game than just the vehicles they can buy., not sure what point you are trying to prove.

i was assuming that it was only vehicles but its fine lol

Yeah, you join then it makes the buttons, how would I go about putting it into the server

why dont you just make the buttons manually so the script doesn’t have to make it

This is how the buttons are made

for i,v in pairs(carTable) do
	local new = carTemplate:Clone()
	new.Name = v[1]
	new.CarName.Text = v[1]
	new.CarPrice.Text = v[2]

	new.Parent = script.Parent:WaitForChild("ScrollingFrame")
	
	
	new.PurchaseButton.MouseButton1Down:Connect(function()
		
		current = v
		game.ReplicatedStorage.CarDealerEvents.Remotes.buyCar:FireServer(current, game.Players.LocalPlayer:WaitForChild("PlayerStats").Bank.Value, new.CarName.Text)
	end)
		

There’s no need to have it on the server, make a remote event and have the client do it. ex:

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

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

	if price and plrMoney.Value >= price then
		print(plrMoney.Value, plrMoney.Value - price, price)
		plrMoney.Value -= price
		events.Remotes:WaitForChild("buyCar"):FireClient(plr, vehicle, false)
	else
		print(price, plrMoney.Value >= price)
	end
end)
--client script
local plr = game.Players.LocalPlayer

events.Remotes:WaitForChild("buyCar").OnClientEvent:Connect(function(vehicle, visible)
	local scrf = plr.PlayerGUI.CarSpawner.Selector.ScrollingFrame
	local vehiclef = scrf:FindFirstChild(vehicle)

	if vehiclef then
		vehiclef.PurchaseButton.Visible = visible
	end
end)

Also, make sure to define events in the client script.

Where would I put this client and how should I define,

The local script should go into StarterGUI and you should define events just like you did in the server script.