I have a bank system and i want to make transfers to offline people. but there is something wrong. what have i done. i made a database so when people come only it saved there name and id. when i want to transfer to the people that have played it calls that database so i can have an id from that player. so i get a list from names and ids and can choose from that. it save the date as value in the game so i can access it with other scripts. in a other script i say get the value and make a name for the database with player-id and a name behind it like bankcoins so u get as id -> playeruserid-bankcoins <- the i set that with async so its saved with the value i want to give from my bank.
then when the player comes online it check the ->playeruserid-bankcoins<- database if there is some in it. when something in it add it to his original bank coins.
now the problem. when i transfer to some one else (so not me) and i go offline and i come back online. it give me back what i give the other player. why its not even save on my id number.
here are the codes:
script in serverscriptservice
local DataStore2 = require(1936396537) -- <-- Data store
local DataStoreName = game.ReplicatedStorage.Values.ServerName.Value
local DataStoreService = game:GetService("DataStoreService") -- <-- Data store
local ServerData = DataStoreService:GetDataStore(DataStoreName) -- <-- Data store
game.Players.PlayerAdded:Connect(function(player)
local BankCoinsDataStore = DataStore2("BankCoins",player) -- <-- Data store
local NameData = DataStoreService:GetDataStore("PlayerNameData") -- <-- Data store
local IdData = DataStoreService:GetDataStore("PlayerIdData") -- <-- Data store
local spelerscount = game.ReplicatedStorage.Values.SpelersCount
local ServerId = game.ReplicatedStorage.Values.ServerId.Value
local i = spelerscount.Value
local newi = spelerscount.Value + 1
local found = false
-- check the players i have
for i = spelerscount.Value, 0, -1 do
local pname = NameData:GetAsync(i)
local pid = IdData:GetAsync(i)
if pid == player.UserId and pname == player.Name then
found = true
print("Old Player")
end
end
-- if not exists then add it
if found == false then
NameData:SetAsync(newi, player.Name)
IdData:SetAsync(newi, player.UserId)
spelerscount.Value = newi
local DataStoreName = game.ReplicatedStorage.Values.ServerName.Value
local ServerDataStore = game:GetService("DataStoreService")
-- Get the data from DataStoreName
local ServerData = ServerDataStore:GetDataStore(DataStoreName)
local spelercountdata = (ServerId.."-"..spelerscount.Name)
ServerData:SetAsync(spelercountdata,spelerscount.Value)
print("New Player")
end
-- the bank part im talking about
-- make the name
local OTCV = {player.UserId.."-OTCV"}
local OTGV = {player.UserId.."-OTGV"}
--get the database
local OTCGC = ServerData:GetAsync(OTCV) -- <-- Data store
wait(7)
local OTGGG = ServerData:GetAsync(OTGV) -- <-- Data store
wait(7)
--if its nothing make it 0
if OTCGC == false or nil then
ServerData:SetAsync(OTCV,0) -- <-- Data store
OTCGC = 0
end
wait(7)
if OTGGG == false or nil then
ServerData:SetAsync(OTGV,0) -- <-- Data store
OTGGG = 0
end
wait(7)
-- if there is some thing add to bank account and save that there is nothing to get any more (so make it 0) that if he comes online again he cant get the same amount it was
if OTCGC > 0 then
BankCoinsDataStore:Increment(OTCGC,defaultCoinsValue) -- <-- Data store
ServerData:SetAsync(OTCV,0)-- <-- Data store
end
wait(7)
if OTGGG > 0 then
BankGoldDataStore:Increment(OTGGG,defaultGoldValue)-- <-- Data store
ServerData:SetAsync(OTGV,0)-- <-- Data store
end
end)
script from my gui screen to get the names
local DataStore2 = require(1936396537)-- <-- Data store
local DataStoreService = game:GetService("DataStoreService")-- <-- Data store
local Players = game:GetService("Players"):GetPlayers()
local map = script.Parent
local Frame = map.Frame
local Ui = map.ScrollingFrame
local player = map.Parent.Parent
wait(1)
local NameData = DataStoreService:GetDataStore("PlayerNameData")
local IdData = DataStoreService:GetDataStore("PlayerIdData")
local spelerscount = game.ReplicatedStorage.Values.SpelersCount
local i = spelerscount.Value
if i ~= 0 then
for i = spelerscount.Value, 0, -1 do
local pname = NameData:GetAsync(i)-- <-- Data store
local pid = IdData:GetAsync(i)-- <-- Data store
if pid ~= player.UserId and pname ~= player.Name and pid ~= nil and pname ~= nil then
local copy = Frame:Clone()
copy.AName.Value = pname
copy.AID.Value = pid
copy.Visible = true
copy.a.Text = pname
copy.aid.Text = pid
copy.a.Name = pname
copy.aid.Name = pid
copy.Name = pname
copy.Ja.Disabled = false
copy.Parent = Ui
end
end
end
next script when i chose that player
wait(1)
local button = script.Parent.BName
local Give = game.ReplicatedStorage.Gui.OTGFrame
local Frame = script.Parent
local Gui = Frame.Parent.Parent
local p = Gui.Parent.Parent
Frame.BBName.Value = p.Name
button.MouseButton1Down:connect(function()
local copy = Give:Clone()
copy.Parent = Gui
copy.AName.Value = Frame.AName.Value
Frame.Visible = false
Frame.Parent = copy
local SF = Gui.ScrollingFrame
SF:Destroy()
end)
and then the next script to set amount and save it with async so the player can get it when he come online
local DataStore2 = require(1936396537)-- <-- Data store
local DataStoreName = game.ReplicatedStorage.Values.ServerName.Value
-- Get service
local ServerDataStore = game:GetService("DataStoreService")-- <-- Data store
-- Get the data from DataStoreName
local ServerData = ServerDataStore:GetDataStore(DataStoreName)-- <-- Data store
local Players = game:GetService("Players"):GetPlayers()
local defaultCoinsValue = 0
wait(1)
local Okebutton = script.Parent.OkeButton
local DownButton = script.Parent.DownButton
local Down10Button = script.Parent.Down10Button
local UpButton = script.Parent.UpButton
local Up10Button = script.Parent.Up10Button
local close = script.Parent.CloseButton
local GaveBankCoinsDataStore
local GiveNamea = script.Parent.AName
local GiveNameb = script.Parent.AName.Value
local GiveIda = script.Parent[GiveNameb].AID
local GaveNamea = script.Parent[GiveNameb].BBName
for i, player in pairs(Players) do
if player.Name == GaveNamea.Value then
GaveBankCoinsDataStore = DataStore2("BankGold",player)-- <-- Data store
end
end
local GaveAmount = GaveBankCoinsDataStore:Get(defaultCoinsValue)-- <-- Data store
local BValue = script.Parent[GiveNameb].AValue
local CValue = GaveAmount
script.Parent.AmountLabel.Text = BValue.Value
script.Parent.AAmountLabel.Text = CValue
local oldValue
local OTCVData = {GiveIda.Value.."-OTGV"}-- <-- Data store
name or id from player to give to
UpButton.MouseButton1Down:Connect(function(p)
BValue.Value = BValue.Value + 1
script.Parent.AmountLabel.Text = BValue.Value
end)
Up10Button.MouseButton1Down:Connect(function(p)
BValue.Value = BValue.Value + 10
script.Parent.AmountLabel.Text = BValue.Value
end)
DownButton.MouseButton1Down:Connect(function(p)
if BValue.Value > 0 then
BValue.Value = BValue.Value - 1
script.Parent.AmountLabel.Text = BValue.Value
end
end)
Down10Button.MouseButton1Down:Connect(function(p)
if BValue.Value > 9 then
BValue.Value = BValue.Value - 10
script.Parent.AmountLabel.Text = BValue.Value
end
end)
close.MouseButton1Down:Connect(function()
local Map = script.Parent.Parent
local Screen = Map.Parent.Screen
Screen.Value = false
Map:Destroy()
end)
Okebutton.MouseButton1Down:connect(function(p)
if CValue >= BValue.Value then
GaveBankCoinsDataStore:Increment(-BValue.Value,defaultCoinsValue)-- <-- Data store
oldValue = ServerData:GetAsync(OTCVData)-- <-- Data store
if oldValue == nil or oldValue == false then
oldValue = 0
end
local newValue = oldValue + BValue.Value
ServerData:SetAsync(OTCVData, newValue)-- <-- Data store
script.Parent.OkeButton.Text = "Done"
wait(3)
local Map = script.Parent.Parent
local Screen = Map.Parent.Screen
Screen.Value = false
Map:Destroy()
else
script.Parent.OkeButton.Text = "Not enuf"
end
end)
so what do u think? what did i wrong? why do i get the amount back i gave away while i saved it on an other id?
thanks for the help already

6 comments
Personally, I prefer to use datastore. I find it to be way easier and easy to access.With the normal datastore, I could give you a code example in >50 lines
i use datastore already for ingame. but cant use datastore with only a playerid, u get an error, so i have to make the save my self with a set and get async.
mc3334 read the script first befor u command something then u saw i used already database
not true^
Im writing a solution rn, just give me a couple more mins to finish it up.
ok, I just wrote what I think is my longest answer ever