Hello!
I am trying to make a system where you can rate a map (like/dislike). I want those values to be saved and updated across all servers. I already have the datastore script written but I am worried about these things:
-
I am using Updateasync, but I am worried if I used it correctly and it won’t prevent overwriting data.
-
I noticed that the map votes only update only when you rejoin a server even though I am updating the datastore every 15 seconds (for testing purposes and will likely take longer in the final product).
local DataStoreService = game:GetService("DataStoreService")
local VotingStore = DataStoreService:GetDataStore("Votes")
local ServerStorage = game:GetService("ServerStorage")
local VotingValues = ServerStorage.VotingValues
local function LoadVotes()
local data
local success, Error = pcall(function()
data = VotingStore:GetAsync("VotesData")
end)
if success then
if data then
print("Votes Data Loaded!")
VotingValues.Alder.Likes.Value = data.Alder.Likes
VotingValues.Alder.Dislikes.Value = data.Alder.Dislikes
end
else
print(Error)
end
end
local function UpdateVotes(CurrentData, keyInfo)
local Mydata = {
Alder = {Likes = VotingValues.Alder.Likes.Value, Dislikes = VotingValues.Alder.Dislikes.Value}
}
local success, Error, keyInfo = pcall(function()
VotingStore:UpdateAsync("VotesData", function(ov)
for i,v in pairs(Mydata) do
ov[i] = v
end
return ov
end)
end)
if success then
print("Votes Data Updated!")
end
end
while true do
LoadVotes()
wait(10)
UpdateVotes()
end
Thanks!