Hey, devfourm. I’m working on a game, I’ve decided to add a currency system to the game to allow users to continue buying builds ingame. I’ve made a simple currency handler but I can’t tell why the datastore is not working. I’m getting nothing in output but it’s not working. Tell me if you can help!
–
The Script
–
local Players = game:GetService("Players") -- Don't mind from here
local DataStoreService = game:GetService("DataStoreService")
local WalletDatastore = DataStoreService:GetDataStore("WalletDataStore")
local BankDatastore = DataStoreService:GetDataStore("BankDatastore")
Players.PlayerAdded:Connect(function(Player)
local DataFolder = Instance.new("Folder", Player)
DataFolder.Name = "Data"
if Player:GetRankInGroup(9039838) >= 254 then
local ModValue = Instance.new("BoolValue", DataFolder)
ModValue.Name = "Moderator"
ModValue.Value = true
end
end) -- To here. I just need help below, thanks! \/
Players.PlayerAdded:Connect(function(Player)
local UserID2 = Player.UserId
local Currency1 = WalletDatastore:GetAsync(UserID2)
if Currency1 == nil then
Currency1 = 0
WalletDatastore:GetAsync(UserID2, Currency1)
end
local FolderData = Player:WaitForChild("Data")
local Wallet = Instance.new("IntValue", FolderData)
Wallet.Name = "Wallet"
Wallet.Value = Currency1
Wallet.Changed:Connect(function(NewValue)
WalletDatastore:SetAsync(UserID2, NewValue)
end)
end)
Players.PlayerAdded:Connect(function(Player)
local UserID1 = Player.UserId
local Currency2 = BankDatastore:GetAsync(UserID1)
if Currency2 == nil then
Currency2 = 0
BankDatastore:GetAsync(UserID1, Currency2)
end
wait()
local DatFolder = Player:WaitForChild("Data")
local Bank = Instance.new("IntValue", DatFolder)
Bank.Name = "Bank"
Bank.Value = Currency2
Bank.Changed:Connect(function(NewValue)
BankDatastore:SetAsync(UserID1, NewValue)
end)
end)