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

My Update async isnt working no errors?

Asked by 4 years ago
local DS = game:GetService("DataStoreService"):GetDataStore('myDatastoreTesting')






game.Players.PlayerAdded:Connect(function(plr)
    local Val = Instance.new("IntValue")
    local GotAsync = DS:GetAsync(plr.UserId)
    Val.Name = plr.UserId
    print(GotAsync)
    Val.Parent = workspace
    Val.Value = DS:GetAsync(plr.UserId)




end)


game.Players.PlayerRemoving:Connect(function(plr)

    local val = game.Workspace[plr.UserId]

    DS:UpdateAsync(plr.UserId,    function(oldVal)

        oldVal = val.Value

        print(oldVal)
        return oldVal
    end)

end)

1 answer

Log in to vote
0
Answered by
B_rnz 171
4 years ago
Edited 4 years ago

Since I can't really test out scripts in my studio, i'll just 'think' at what could be wrong with this.

Lines 22-26:

You're getting Player.UserID, in workspace, which is a NOT valid member of Workspace, so the output would show something like 1231261 is not a valid member of workspace So try using plr `instead:

game.Players.PlayerRemoving:Connect(function(plr)

    local val = game.Workspace[plr] 

    DS:UpdateAsync(plr.UserId,    function(oldVal)

        oldVal = val.Value

        print(oldVal)
        return oldVal
    end)

end)

Hope this works!

Ad

Answer this question