In these two scripts, I am trying to somewhat optimize my way of changing the data in the datastore when it is changed in game. I’ve come across two problems:
I’ve never had the issue where it experienced an error loading, and even though I’ve encountered the “does not return exactly one value” issue before, I still don’t know what I’ve done wrong in this place.
Here’s the module and a part of the data manager script.
DataMod:
local players = game:GetService("Players")
local dataMod = {}
function dataMod.updateData(dataType, playerData, player, referenceName)
dataType.Changed:Connect(function()
playerData[player.UserId].referenceName = dataType.Value
end)
end
return dataMod
DataManager:
local TimePlayedSeconds = playerData[player.UserId].TimePlayedSeconds
local TimePlayedMinutes = playerData[player.UserId].TimePlayedMinutes
local TimePlayedHours = playerData[player.UserId].TimePlayedHours
timeplayed_seconds.Value = TimePlayedSeconds
timeplayed_minutes.Value = TimePlayedMinutes
timeplayed_hours.Value = TimePlayedHours
dataMod.updateData(timeplayed_seconds, playerData, player, TimePlayedSeconds)
dataMod.updateData(timeplayed_minutes, playerData, player, TimePlayedMinutes)
dataMod.updateData(timeplayed_hours, playerData, player, TimePlayedHours)
Hopefully this all helps and you’re able to help resolve my issue! Thanks!
Edit: Also if you have any other tips to make this better in any way, send them my way too