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