Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Money Duplicating with data-store leader-board + .Changed not working on number-value?

Asked by
NewGPU 36
5 years ago
Edited 5 years ago

(1) Problem: Datastore leaderboard duplicates money when a player joins and leaves quickly What I am trying to accomplish: A solution to the problem above ^

Script:

local datastore = game:GetService("DataStoreService")
local ds2 = datastore:GetDataStore("Redacted")

game.Players.PlayerAdded:connect(function(plr)

 local folder = Instance.new("Folder", plr)
 folder.Name = "stats"

 local wallet = Instance.new("IntValue", folder)
 wallet.Name = "Wallet"

 local bank = Instance.new("IntValue", folder)
 bank.Name = "Bank"

 wallet.Value = 0

 bank.Value = ds2:GetAsync(plr.UserId) or 0
 ds2:SetAsync(plr.UserId, bank.Value)

 bank.Changed:connect(function()
  wait(0.5)
  ds2:SetAsync(plr.UserId, bank.Value)
 end)

end)

(2) Problem: ".Changed" Event is not working with Number/IntValue What I want: For it to actually work and update the text.

game.Players.LocalPlayer.stats.Bank.Changed:Connect(function()
    script.Parent.BankAmount.Text = fBank
dddddddd
game.Players.LocalPlayer.stats.Wallet.Changed:connect(function()
    script.Parent.WalletAmount.Text = fWallet
end)

AND this doesn't work either

game.Players.LocalPlayer.stats.Bank.Value.Changed:Connect(function()
    script.Parent.BankAmount.Text = fBank
end)

game.Players.LocalPlayer.stats.Wallet.Value.Changed:connect(function()
    script.Parent.WalletAmount.Text = fWallet
end)

Note: Reposted this due to it not being answered.

1 answer

Log in to vote
0
Answered by
NewGPU 36
5 years ago

Solved,

(1)

local DSService = game:GetService("DataStoreService"):GetDataStore("Redacted")

game.Players.PlayerAdded:Connect(function(plr)
    local uk = 'id-'..plr.userId
    local stats = Instance.new('IntValue',plr)
    local VL1 = Instance.new('IntValue')
    local VL2 = Instance.new('IntValue')
    stats.Name = 'stats'
    VL1.Parent = stats
    VL1.Name = 'Bank'

    VL2.Parent = stats
    VL2.Name = 'Wallet'

    local  GetSaved = DSService:GetAsync(uk)
    if GetSaved then
        VL1.Value = GetSaved[1]
        VL2.Value = 0
    else
        local NFS = {VL1.Value}
        DSService:SetAsync(uk, NFS)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local uk = 'id-'..plr.userId
    local ST = {plr.stats.Bank.Value}
    DSService:SetAsync(uk, ST)
end)~~~~~~~~~~~~~~~~

(2)

script.Parent.Parent.Parent.Parent.stats.Bank.Changed:Connect(function() print("Bank") local eBank = AddCommas(game.Players.LocalPlayer.stats.Bank.Value) script.Parent.BankAmount.Text = "$"..eBank end)

script.Parent.Parent.Parent.Parent.stats.Wallet.Changed:Connect(function() print("Wallet") local eWallet = AddCommas(game.Players.LocalPlayer.stats.Wallet.Value) script.Parent.WalletAmount.Text = "$"..eWallet end)

~~~~~~~~~~~~~~~~~

Ad

Answer this question