'Unable to cast value to function' while using UpdateAsync

Hello everyone!

Today I was learning how to use DataStoreService and wrote simple scripts (Local Script and just Script) which add +1 value every second to player’s leaderstats and supposed to set async when player joins first time, upload async by get async and remote event into leaderstats and save it when player lefts.

My day be so fine, then boom:

image

Only part with player removing doesn’t work well, here is a script of it:

players.PlayerRemoving:Connect(function(player)
	event.OnServerEvent:Connect(function(player, aaa)
		value:UpdateAsync("TextValue", aaa) -- the stroke with error
	end)
end)

It has to get player’s leaderstats’ current value and update it every time when player lefts. Somehow it has an error which I don’t know how to fix. I searched some solutions on DevForum. Someone had similar problem and the solution was this:

It might be related, but im not sure what i can do in this situation. If someone knows how to fix this, please reply. Thanks in advance and have a nice day!

players.PlayerRemoving:Connect(function(player)
    event.OnServerEvent:Connect(function(player, aaa)
        value:UpdateAsync("TextValue", function(oldValue)
            return aaa
        end) -- the stroke with error
    end)
end)
2 Likes