How do I get this Robbery system to take the money that's "stolen" and store it in my DataStorage?
I've tried multiple methods but I just can't seem to get it to work, I'd really appreciate some support.
I absolutely do not want to use the standard ROBLOX leaderboard, but the moneySystem I've put together that makes use of ScreenGuis, sorry if this is a really simple fix but I'm quite new to scripting!
bankCashGiver
02 | local playerfound = false |
03 | local player = game:GetService( "Players" ) |
08 | local cash = game:GetService( "DataStoreService" ):GetDataStore( "MoneyData" ) |
12 | game.Players.PlayerAdded:Connect( function (plr) |
16 | local key = "id-" .. plr.UserId |
19 | saveData = cash:GetAsync(key) |
22 | cash.Value = saveData [ 1 ] |
26 | cash:SetAsync(key,save) |
31 | function CreateRegion 3 FromPart(Part) |
32 | return Region 3. new(Part.Position-(Part.Size/ 2 ),Part.Position+(Part.Size/ 2 )) |
35 | function GetPlayersInPart(part) |
36 | local region = CreateRegion 3 FromPart(part) |
37 | local partsInRegion = workspace:FindPartsInRegion 3 (region, nil , math.huge ) |
41 | for i,Part in pairs (partsInRegion) do |
42 | local player = game.Players:GetPlayerFromCharacter(Part.Parent) |
45 | for i, v in pairs (Players) do |
46 | if Players [ i ] .Name = = player.Name then |
51 | if playerfound = = false then |
52 | table.insert(Players,player) |
58 | for i, v in pairs (Players) do |
60 | if Players [ i ] .Robbing.Value = = false then |
61 | game.ReplicatedStorage.ShowRobberyGUI:FireClient(Players [ i ] ) |
63 | Players [ i ] .Robbing.Value = true |
64 | if Players [ i ] .cashCollectedData.Value < 1500 then |
65 | Players [ i ] .cashCollectedData.Value = Players [ i ] .cashCollectedData.Value + 10 |
72 | GetPlayersInPart(game.Workspace.Detector) |
DoorDetector (whenever you leave the building it would deposit the money into the account.)
01 | local replicatedStorage = game.ReplicatedStorage |
02 | local MoneyData = game.ReplicatedStorage:FindFirstChild( "MoneyData" ) |
04 | game.Players.PlayerAdded:Connect( function (plr) |
05 | local MoneyData = game.ReplicatedStorage:FindFirstChild( "MoneyData" ) |
06 | local sourcePlayer = MoneyData:FindFirstChild(plr.Name) |
11 | script.Parent.Touched:Connect( function (hit) |
12 | if hit.Parent:FindFirstChild( "HumanoidRootPart" ) then |
13 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
14 | if player.Robbing.Value = = true then |
15 | game.ReplicatedStorage.HideRobberyGUI:FireClient(player) |
16 | replicatedStorage.MoneyData.sourcePlayer.Cash.Value = replicatedStorage.MoneyData.sourcePlayer.Cash.Value + replicatedStorage.cashCollectedData.Value |
17 | replicatedStorage.cashCollectedData.Value = 0 |
18 | replicatedStorage.Robbing.Value = false |
"Leaderboard"
01 | game.Players.PlayerAdded:Connect( function (player) |
03 | local leaderstats = game.ReplicatedStorage:GetChildren( "MoneyData" ) |
04 | leaderstats.Name = "MoneyData" |
06 | local money = game.ReplicatedStorage.MoneyData:GetChildren( "Cash" ) |
09 | local cc = Instance.new( "IntValue" , player) |
10 | cc.Name = "cashCollectedData" |
12 | local robbing = Instance.new( "BoolValue" , player) |
13 | robbing.Name = "Robbing" |
16 | player.CharacterAdded:connect( function (char) |
17 | player.Robbing.Value = false |
18 | player.cashCollectedData.Value = 0 |
Actual money GUI "LocalScript"
01 | local player = game.Players.LocalPlayer |
04 | local moneyData = game.ReplicatedStorage:WaitForChild( "MoneyData" ) |
05 | local playerCash = moneyData:WaitForChild(player.Name) |
07 | script.Parent.cashDisplay.Text = "$ " ..playerCash.Cash.Value |
08 | playerCash.Cash.Changed:connect( function () |
09 | script.Parent.cashDisplay.Text = "$ " ..playerCash.Cash.Value |
Any support would be heavily appreciated, been stumped for quite some time now!
I should be able to provide any information if you need anything else.