Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Start of Credit Functions
- local DataStoreService = game:GetService("DataStoreService")
- local CreditDatastore = DataStoreService:GetDataStore("CreditSystemDev")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Players = game:GetService("Players")
- local FirebaseAPI = require(script.FirebaseService)
- local Database = FirebaseAPI:GetFirebase("Nitro")
- local configfile = require(script.configData)
- local dataConfig = configfile.dataConfig
- local Credit = { }
- local RunService = game:GetService("RunService")
- -- sets the player up & if they already have a save, load that save in and not give them the default starter cash
- Credit.SetupPlayer = function(Player)
- for _, plr in next, game.Players:GetPlayers() do
- local Data = Instance.new("Folder")
- Data.Name = "Data"
- Data.Parent = plr
- local Successful, Save = Credit:LocateSave(Player)
- local Credits = Instance.new("IntValue")
- Credits.Name = "Credits"
- Credits.Parent = Data
- Credits.Value = Save or dataConfig.StarterCash
- end
- end
- -- locates the save of the player
- function Credit:LocateSave(Player)
- for _, plr in next, game.Players:GetPlayers() do
- local UserId = plr.UserId
- local DataReturn = CreditDatastore:GetAsync(UserId)
- return DataReturn ~= nil, DataReturn
- end
- end
- -- saves the player data
- function Credit:SavePlayer(Player)
- if RunService:IsStudio() then
- return
- end
- local UserId = Player.UserId
- assert(type(UserId) == "number", "Credit:LocateSave() failed! (Invalid UserId)")
- local Data = Player:WaitForChild("Data"):FindFirstChild("Credits")
- if not Data then
- Data = { }
- Data["Value"] = dataConfig.StarterCash
- end
- local Successful = pcall(function()
- CreditDatastore:SetAsync(UserId, Data.Value)
- end)
- if not Successful then
- delay(dataConfig.RetryTime, function()
- Player:SavePlayer(Player)
- end)
- error("[DATASTORE] UNSUCCESSFUL SAVE OF ".. Player.Name.. "! RETRYING")
- else
- print("[DATASTORE] SUCCESSFUL SAVE OF ".. Player.Name)
- end
- end
- -- goes through and saves all players data
- Credit.SaveAllPlayers = function()
- if RunService:IsStudio() then
- print("You're in studio, you cannot test if this works.")
- return
- end
- for _, Player in next, game.Players:GetPlayers() do
- local Credits = Player:FindFirstChild("Data"):FindFirstChild("Credits").Value
- Credit:SavePlayer(Player)
- end
- end
- -- updates the player's text on gui
- function Credit.Update(player)
- for _, Player in next, game.Players:GetPlayers() do
- local Credits = Player:WaitForChild("Data"):FindFirstChild("Credits").Value
- Player:WaitForChild("PlayerGui"):WaitForChild("Credits").CreditTex.TextLabel.Text = "Credits: " .. Credits
- end
- end
- -- gives nitro boost perks whenever boosted our server
- function Credit.Nitro(player)
- print("starting up nitro")
- -- gives the players that nitro boosted our server, some perks, enjoy :D
- -- setting up firebase
- local FirebaseAPI = require(script.FirebaseService)
- local NiDatabase = FirebaseAPI:GetFirebase("Nitro")
- local PlayerData = NiDatabase:GetAsync(player.UserId.."/nitro")
- -- giving the players perks if the value retuns true
- if PlayerData then
- local Credit = player:WaitForChild("Data"):WaitForChild("Credits").Value
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- Credit += 10000
- end
- print("completed nitro")
- end
- return Credit
- -- ending of the credit function script
Advertisement
Add Comment
Please, Sign In to add comment