How to get local player in DataStore2?
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 >
1. Type player name
2. Type amount
3. 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.
01 | local DataStore 2 = require(game.ServerScriptService:WaitForChild( "DataStore2" )) |
03 | local defaultValue = 15000 |
10 | game.Players.PlayerAdded:Connect( function (plr) |
12 | local cashDataStore = DataStore 2 ( "Cash" ,plr) |
13 | local leaderstats = Instance.new( "Folder" ,plr) |
14 | leaderstats.Name = "leaderstats" |
16 | local cash = Instance.new( "IntValue" ,leaderstats) |
19 | local function cashUpdate(UpdatedValue) |
21 | cash.Value = cashDataStore:Get(UpdatedValue) |
23 | cashUpdate(defaultValue) |
24 | cashDataStore:OnUpdate(cashUpdate) |
27 | game.Players.PlayerAdded:Connect( function (player) |
29 | local button = player.PlayerGui.Phone:WaitForChild( "Base" ):WaitForChild( "Screen" ):WaitForChild( "AppScreens" ):WaitForChild( "FunkyPay" ).TextButton |
30 | local Amount = player.PlayerGui.Phone:WaitForChild( "Base" ):WaitForChild( "Screen" ):WaitForChild( "AppScreens" ):WaitForChild( "FunkyPay" ).Amount.Text |
31 | local Player = player.PlayerGui.Phone:WaitForChild( "Base" ):WaitForChild( "Screen" ):WaitForChild( "AppScreens" ):WaitForChild( "FunkyPay" ).Player.Text |
32 | local CashDataStore = DataStore 2 ( "Cash" ,player) |
33 | local function onButtonActivated() |
34 | CashDataStore:Icrement(-Amount) |
37 | button.Activated:Connect(onButtonActivated) |
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?