I was following RobloxDevForum tutorial on making DataStore2, where they used "DATASTORE:increment()" But i found problem, I tried to make money transfer system to give money to any player. It works like this >
- Type player name
- Type amount
- Press transfer But I cant get local player for identify the "Transfer, amount and player name" button. I also cant create "local cashDataStore = DataStore2("Cash",plr)" cause this script uses plr, which i got by PlayerAdded, sadly playeradded isnt looped so i cant use it for making GUI work. Here is the script.
local DataStore2 = require(game.ServerScriptService:WaitForChild("DataStore2"))
local defaultValue = 15000
amount = 250
timedelay = 60
currency = "Cash"
game.Players.PlayerAdded:Connect(function(plr)
local cashDataStore = DataStore2("Cash",plr)
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue",leaderstats)
cash.Name = "Cash"
local function cashUpdate(UpdatedValue)
cash.Value = cashDataStore:Get(UpdatedValue)
end
cashUpdate(defaultValue)
cashDataStore:OnUpdate(cashUpdate)
end)
game.Players.PlayerAdded:Connect(function(player)
local button = player.PlayerGui.Phone:WaitForChild("Base"):WaitForChild("Screen"):WaitForChild("AppScreens"):WaitForChild("FunkyPay").TextButton
local Amount = player.PlayerGui.Phone:WaitForChild("Base"):WaitForChild("Screen"):WaitForChild("AppScreens"):WaitForChild("FunkyPay").Amount.Text
local Player = player.PlayerGui.Phone:WaitForChild("Base"):WaitForChild("Screen"):WaitForChild("AppScreens"):WaitForChild("FunkyPay").Player.Text
local CashDataStore = DataStore2("Cash",player)
local function onButtonActivated()
CashDataStore:Icrement(-Amount)
end
button.Activated:Connect(onButtonActivated)
end)
breakdown at line 29, the problematic place. Another problem is, i dont know how to actually make the transfer, cause it uses increment, and i dont really know how to change others player increment/amount of money with this script, increment works only for local player (by PlayerAdded). Any help from average scripters or with scripters who already had the same problem and know the solve?

2 comments
We'd need to see the module of the datastore to be able to help out some more.
https://web.roblox.com/library/3612128667/DataStore2-Code-Refactor, i used this module