Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local PlayerData = require(game.ServerStorage.PlayerData)
- local HttpService = game:GetService("HttpService")
- local PlayerCars = {}
- game.Players.PlayerAdded:Connect(function(plr)
- local BankStatus = Instance.new("IntValue",plr)
- BankStatus.Name = "BankStatus"
- BankStatus.Value = PlayerData:GetDataYielding(plr, "BankStatus")
- local lstats = Instance.new("Folder",plr)
- lstats.Name = "leaderstats"
- local USD = Instance.new("IntValue",lstats)
- USD.Name = "USD"
- USD.Value = PlayerData:GetData(plr, "USD")
- local Cars = Instance.new("StringValue", lstats)
- Cars.Name = "Cars"
- end)
- game.ReplicatedStorage.BankManager.OnServerEvent:Connect(function(plr,command,amt)
- if amt and amt > 0 then
- if command == "Withdraw" then
- if PlayerData:GetData(plr, "BankStatus") >= amt then
- PlayerData:IncrementData(plr, "USD", amt)
- PlayerData:IncrementData(plr, "BankStatus", -amt)
- end
- elseif command == "Deposit" then
- if PlayerData:GetData(plr, "USD") >= amt then
- PlayerData:IncrementData(plr, "BankStatus", amt)
- PlayerData:IncrementData(plr, "USD", -amt)
- end
- end
- end
- end)
- game.ReplicatedStorage.GunBuying.OnServerEvent:Connect(function(plr,gun)
- local price = gun.Price.Value
- if PlayerData:GetData(plr, "USD") >= price then
- PlayerData:IncrementData(plr, "USD", price)
- local gunclone = gun:Clone()
- gunclone.Parent = plr.Backpack
- end
- end)
- local cardebounce = false
- game.ReplicatedStorage.CarBuying.OnServerEvent:Connect(function(plr,car)
- if PlayerData:GetData(plr, "Cars") ~= nil then
- Cars = HttpService:JSONDecode(PlayerData:GetData(plr, "Cars"))
- else
- Cars = {}
- end
- if not cardebounce then
- local price = car.Price.Value
- if PlayerData:GetData(plr, "USD") >= price then
- if table.find(Cars, tostring(car)) == nil then
- cardebounce = true
- PlayerData:IncrementData(plr, "USD", -price)
- local CarClone = car:Clone()
- CarClone.Parent = workspace
- Cars[#Cars+1] = tostring(car)
- if table.find(PlayerCars, tostring(plr)) then
- print("Has data")
- if PlayerCars[tostring(plr)].car then
- print("Has car")
- PlayerCars[tostring(plr)].car:Destroy()
- end
- end
- PlayerCars[tostring(plr)] = car
- plr.leaderstats.Cars.Value = HttpService:JSONEncode(Cars)
- PlayerData:SetData(plr, "Cars", HttpService:JSONEncode(Cars))
- wait(5)
- cardebounce = false
- end
- end
- end
- end)
- local cardebounce2 = false
- game.ReplicatedStorage.CarSpawning.OnServerEvent:Connect(function(plr,car)
- local Cars = HttpService:JSONDecode(plr.leaderstats.Cars.Value)
- print("1")
- if not cardebounce2 then
- print("2")
- if table.find(Cars, tostring(car)) then
- print("3")
- cardebounce2 = true
- local CarClone = car:Clone()
- CarClone.Parent = workspace
- if table.find(PlayerCars, tostring(plr)) then
- if PlayerCars[tostring(plr)].car then
- PlayerCars[tostring(plr)].car:Destroy()
- end
- end
- PlayerCars[tostring(plr)] = car
- wait(5)
- cardebounce2 = false
- end
- end
- end)
- while wait(1) do
- for x,v in pairs(game.Players:GetPlayers()) do
- PlayerData:IncrementData(v, "USD", script:FindFirstChild(tostring(v.Team)).Value)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement