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

What went wrong with my tool to money script when they leave?

Asked by 8 years ago

There is no error.

local DSService = game:GetService('DataStoreService'):GetDataStore('Hamburger223232')
game.Players.PlayerAdded:connect(function(plr)
    -- Define variables
    local uniquekey = 'id-'..plr.userId
    local leaderstats = Instance.new('IntValue', plr)
    local savevalue =  Instance.new('IntValue')
    leaderstats.Name = 'leaderstats'
    savevalue.Parent = leaderstats
    savevalue.Name = 'Tokens'

    -- GetAsync
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        savevalue.Value = GetSaved[1]
    else
        local NumbersForSaving = {savevalue.Value}
        DSService:SetAsync(uniquekey, NumbersForSaving)

    end
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Tokens.Value}
local sword1 = plr.Backpack:FindFirstChild("Venomshank")
local sword2 = plr.Backpack:FindFirstChild("Firebrand")
local sword3 = plr.Backpack:FindFirstChild("Windforce")
if sword1 then 
    Savetable = Savetable+50
end
if sword2 then
    Savetable = Savetable + 100
end
if sword3 then
    Savetalbe = Savetable + 150
end
DSService:SetAsync(uniquekey, Savetable)    



end)
0
You aren't giving much of an explanation. The only error I see looking directly at it is you attempting to add 50,100, and 150 directly to a table instance. Shawnyg 4330 — 8y
0
Why are you saving different things with the same key? and "Savetable = Savetable+50" will error as its a table. User#5423 17 — 8y
0
You also don't need to create a table. You can make it a regular integer. Shawnyg 4330 — 8y

Answer this question