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