Need help with script!

Hello everyone I have found a bug in my game were the player can’t buy or sell cars but in my main game it works I changed Cash datastores on the dev place so could that be the reason please tell me whats wrong with the scripts!

local ShopCars = game.ServerStorage:WaitForChild(“ShopCars”)
local PurchaseEvent = game.ReplicatedStorage:WaitForChild(“PurchaseCar”)
local SellCarEvent = game.ReplicatedStorage:WaitForChild(“SellCar”) – new
local PurchaseFailedEvent = game.ReplicatedStorage:WaitForChild(“PurchaseCarFailed”)
local AddCarEvent = game.ReplicatedStorage:WaitForChild(“AddCar”)
local RemoveCarEvent = game.ReplicatedStorage:WaitForChild(“RemoveCar”) – new
local GetCarParamsFunc = game.ReplicatedStorage:WaitForChild(“GetCarParams”)
local GetSellPriceFunc = game.ReplicatedStorage:WaitForChild(“GetSellPrice”) – new
local ServerPurchasedCars = game.ServerStorage:WaitForChild(“PurchasedCars”)
local PaintCar = require(game.ReplicatedStorage:WaitForChild(“PaintCarModule”)).PaintCar
local SellPercent = 80 – new

function AddCar(Cost, Cash, PurchasedCars, car, player, carname, color)
if Cost and Cash.Value >= Cost.Value and not PurchasedCars:FindFirstChild(carname) then
local ClonedCar = car:Clone()
if color then
local colorvalue = Instance.new(“Color3Value”, ClonedCar)
colorvalue.Name = “Color”
colorvalue.Value = color
PaintCar(ClonedCar, color)
end
ClonedCar.Parent = PurchasedCars
Cash.Value = Cash.Value - Cost.Value
AddCarEvent:FireClient(player, carname, color)
elseif Cost and Cash.Value < Cost.Value and not PurchasedCars:FindFirstChild(carname) then
PurchaseFailedEvent:FireClient(player, Color3.fromRGB(255, 0, 0), “You don’t have enough money”)
elseif PurchasedCars:FindFirstChild(carname) then
PurchaseFailedEvent:FireClient(player, Color3.fromRGB(255, 0, 0), “You already have this car”)
end
end

PurchaseEvent.OnServerEvent:Connect(function(player, carname, color)
local leaderstats = player:FindFirstChild(“leaderstats”)
local PurchasedCars = ServerPurchasedCars:FindFirstChild(player.Name)
if leaderstats and PurchasedCars then
local car = ShopCars:FindFirstChild(carname)
if car then
local Cash = leaderstats:FindFirstChild("$")
local Cost = car:FindFirstChild(“Cost”)
AddCar(Cost, Cash, PurchasedCars, car, player, carname, color)
end
end
end)

SellCarEvent.OnServerEvent:Connect(function(player, carname) – new
local leaderstats = player:FindFirstChild(“leaderstats”)
local PurchasedCars = ServerPurchasedCars:FindFirstChild(player.Name)
if leaderstats and PurchasedCars then
local car = PurchasedCars:FindFirstChild(carname)
if car then
local Cash = leaderstats:FindFirstChild("$")
local Cost = car:FindFirstChild(“Cost”)
if Cash and Cost then
Cash.Value = Cash.Value + Cost.Value * SellPercent / 100
car:Remove()
RemoveCarEvent:FireClient(player, carname)
end
end
end
end)

function comma_value(n)
local left, num, right = string.match(n, ‘^([^%d]%d)(%d)(.-)$’)
return left … (num:reverse():gsub(’(%d%d%d)’, '%1 '):reverse()) … right
end

function GetSellPrice(player, carname) – new
local ReturnCost = “No cost”
local Car = ShopCars:FindFirstChild(carname)

if Car then
	local Cost = Car:FindFirstChild("Cost")
	if Cost then
		local SellPrice = Cost.Value * SellPercent / 100
		ReturnCost = SellPrice > 0 and '$' .. comma_value(SellPrice) or 'Free'
	end
end
return ReturnCost

end

function GetCarParams(player, carname)
local Result = {}
Result.Name = “No name”
Result.Cost = “No price”
Result.Power = “–”
local Car = ShopCars:FindFirstChild(carname)

if Car then
	local CarName = Car:FindFirstChild("CarName")
	if CarName then
		Result.Name = CarName.Value
	end
	local Cost = Car:FindFirstChild("Cost")
	if Cost then
		Result.Cost = Cost.Value > 0 and '$' .. comma_value(Cost.Value) or 'Free'
	end
	local Power = Car:FindFirstChild("Power")
	if Power then
		Result.Power = Power.Value
	end
end
return Result

end

GetCarParamsFunc.OnServerInvoke = GetCarParams
GetSellPriceFunc.OnServerInvoke = GetSellPrice – new

Datastore:The value used to buy cars is Wallet

local DSS = game:GetService(“DataStoreService”)
local statsDS = DSS:GetDataStore(“statsDS”)

game.Players.PlayerAdded:Connect(function(plr)
local lead = Instance.new(“Folder”)
lead.Name = “leaderstats”
lead.Parent = plr

local Cash = Instance.new("IntValue")
Cash.Name = "Wallet"
Cash.Parent = lead
Cash.Value = 100000

local diam = Instance.new("IntValue")
diam.Name = "Bank"
diam.Parent = lead
diam.Value = 0

--local Reb = Instance.new("IntValue")--
--Reb.Name = "Miles"--

– Reb.Parent = lead–
–Wallet.Value = 0–

local data

local succ, err = pcall(function()
	data = statsDS:GetAsync(plr.UserId.."-stats")
end)

if succ then
	print("success")
	if data then                    --if there was some data then
		print("Got the data from the player datastore")
		Wallet.Value = data[1]
		diam.Value = data[2]
		--Reb.Value = data[3]   --      
	end
else
	print("There was an error while checking: "..plr.Name)
	warn(err)
end

end)

game.Players.PlayerRemoving:Connect(function(plr)
print(“Player is leaving the game!”)
local Wallet = plr.leaderstats.Wallet.Value
local diam = plr.leaderstats.Bank.Value
–local reb = plr.leaderstats.Miles.Value–
print(“Got all the values”)

local data = {Wallet, diam,}

local succ, err = pcall(function()
	statsDS:SetAsync(plr.UserId.."-stats", data)
end)

if succ then
	print("Succesfully saved the data!")
else
	print("There was an error while saving player leaderstats!")
	warn(err)
end

end)

its a little messy to read…
I’ll take a quick look

Isn’t this the same issue highlighted in your other post?

sorta kinda meybe idk bruv why