I hired someone to make me a car pack system that works with my dealership system I adjusted the script and broke it what is wrong with the script and can u guys point out what I should not touch and touch
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
game.Players.PlayerAdded:Connect(function(plr)
game:GetService(“MarketplaceService”):PromptGamePassPurchase(plr, 10903093)
end)
local MarketplaceService = game:GetService(“MarketplaceService”)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, pass_id, was_bought)
if pass_id == 10903093 then – Put gamepass ID
warn(“Purchasing gamepass: succeed!”)
local leaderstats = player:FindFirstChild(“leaderstats”)
local Cash = leaderstats:FindFirstChild(“Wallet”)
AddCar(0, Cash, ServerPurchasedCars:WaitForChild(player.Name), ShopCars.Lambo, player, "Lambo", "White")
AddCar(0, Cash, ServerPurchasedCars:WaitForChild(player.Name), ShopCars.GTR, player, "GTR", "White")
AddCar(0, Cash, ServerPurchasedCars:WaitForChild(player.Name), ShopCars.Hellcat, player, "Hellcat", "White")
for i,v in ipairs(ServerPurchasedCars:WaitForChild(player.Name))do
if v.Name == "Lambo" then
Cash.Value = Cash.Value + 25 -- Put here price of Van
else if v.Name == "Hellcat" then
Cash.Value = Cash.Value + 20 -- Put here price of SRT
else if v.Name == "GTR" then
Cash.Value = Cash.Value + 30 -- Put here price of Track
end
end
end
end
end
end)
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
if carname == “Lambo” or carname == “Hellcat” or carname == "GTR"then
local GamePassId = 10903093
if not MarketplaceService:UserOwnsGamePassAsync(player.UserId,GamePassId) then
local Cash = leaderstats:FindFirstChild(“Wallet”)
local Cost = car:FindFirstChild(“Cost”)
AddCar(Cost, Cash, PurchasedCars, car, player, carname, color)
else
warn(“You already own a gamepass car”)
end
else
local Cash = leaderstats:FindFirstChild(“Wallet”)
local Cost = car:FindFirstChild(“Cost”)
AddCar(Cost, Cash, PurchasedCars, car, player, carname, color)
end
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(“Wallet”)
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
RS
SS