I am trying to make a global like/dislike system where players can like/dislike a map and it updates on other servers. Right now, I am trying to save the data for the likes/dislike system but for some reason, it’s not saving. There are no errors in the output.
Script:
local DataStoreService = game:GetService("DataStoreService")
local VotingStore = DataStoreService:GetDataStore("Votes")
local ServerStorage = game:GetService("ServerStorage")
local VotingValues = ServerStorage.VotingValues
local Mydata = {
Alder = {Likes = VotingValues.Alder.Likes.Value, Dislikes = VotingValues.Alder.Dislikes.Value}
}
local function LoadVote()
local data
local success, Error = pcall(function()
data = VotingStore:GetAsync("VotesData")
end)
if success then
print(data)
VotingValues.Alder.Likes.Value = data.Alder.Likes
print(data.Alder.Likes)
else
print(Error)
end
end
local function SaveVotes()
local success, Error = pcall(function()
VotingStore:UpdateAsync("VotesData", Mydata)
end)
if success then
print("SAVED")
else
print(Error)
end
end
wait(5)
print("LOADING")
LoadVote()
while true do
wait(60)
print("SAVING")
SaveVotes()
end
“Alder” is a map btw.
Do you have Enable Studio Access to API Services turned on?
Yes, I do have it turned on! Is there anything wrong with my code?
Not that I can see of right now. Allow me a few minutes to look at it.
Maybe try this instead.
local function LoadVote()
local data
local success, Error = pcall(function()
data = VotingStore:GetAsync("VotesData")
end)
if success then
print(data)
VotingValues.Alder.Likes.Value = data
print(data.Alder.Likes)
else
print(Error)
end
end
I changed the VotingValues.Alder.Likes.Value = data.Alder.Likes to VotingValues.Alder.Likes.Value = data because in the key you didn’t add that.
The second argument of UpdateAsync is a function. UpdateAsync is typically used to ensure data isn’t lost, but for your implementation you aren’t doing any checks, so just use SetAsync.
1 Like
Still not saving data after changing it to SetAsync and there are still no errors in the output.
Are you running the script in studio or in experience? If you haven’t tested it out of the studio, try testing it in experience.
Just tried it and still not saving. It still prints out 0 when I rejoin even though I raised the votes to 100 in the game.
Got it to work by putting “Mydata” in the LoadVote() function because it wants to get the newest values before it saves. Before whenever the game would start, everything would be at 0 and it would save the same values which are 0 every time.