Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My Update async isnt working no errors?

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

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.