Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

My dataStore loads random data?

Asked by 7 years ago

Some Players in my game have complained about having their Data being changed on entering a different server,some aren't affected and some say that it happens when I use the shutdown all servers button . Apparently the intValues that the datastores are saving are being replaced by random numbers?

I can't seem to find anything wrong with the scripts. I'm hoping someone else can review my script and reassure this should work as intended.

local saveAs = "HS"

local dataStore = game:GetService("DataStoreService"):GetDataStore(saveAs)
local Players = game:GetService("Players")

Players.PlayerAdded:connect(function(player)
    local stats = player:WaitForChild("Hstats")
    local data = dataStore:GetAsync(player.UserId)
    if data then
        for name,value in next, data do
            stats[name].Value = value 
        end
    end
end)

Players.PlayerRemoving:connect(function(player)
    local stats = player:FindFirstChild("Hstat")
    if stats then
        local data = {}
        for _,stat in ipairs(stats:GetChildren()) do
            data[stat.Name] = stat.Value
        end
        dataStore:SetAsync(player.UserId,data)
    end
end)

while wait(61) do
    for _, player in pairs(game.Players:GetChildren()) do
local stats = player:FindFirstChild("Hstat")
    if stats then
        local data = {}
        for _,stat in ipairs(stats:GetChildren()) do
            data[stat.Name] = stat.Value
        end
        dataStore:SetAsync(player.UserId,data)
    end
end
end 



game.OnClose = function()
    wait(10)
end



1 answer

Log in to vote
0
Answered by 7 years ago

This is my best guess. The HS data store probably is used in more games then just yours. Other games are able to change your datastore also, so you should name it something unique, e.x. HS9280924. Also in case someone on scriptinghelpers is trolling, I would not actually post the datastore on here.

0
Did not know about that o_o thanks for letting me know. PsychonautX 15 — 7y
0
Im sorry, but according to the wiki, and some other person, it can only be changed from your game/universe. But thats still the only reason I can think of without seeing your script to get the info. FrostTaco 90 — 7y
Ad

Answer this question