#Help with data on a speed sim

1 messages · Page 1 of 1 (latest)

swift viper
#

heres my code so far

local DSS=game:GetService("DataStoreService")
local SpeedData=DSS:GetDataStore("SpeedData")

local module = {}
local cache={}

function module.LoadData(Player)

    local Success, Data=pcall(function()
        return SpeedData:GetAsync(Player.UserId)
    end)

    cache[Player]=Player.leaderstats.Speed.Value
    return cache[Player]
end



function module.SaveData (player)




    local Data=cache[player]
    print(Data)
    if not Data then return end

    pcall(function()
        SpeedData:SetAsync(player.UserId,Data)
    end)

end

return module
"
and this is my server script``lua

local Players=game:GetService('Players')

local dataHandler=require(script.datahandler)

local DataCache=dataHandler

Players.PlayerAdded:Connect(function(Player)
    

    local leaderstats=Instance.new('Folder',Player)
    leaderstats.Name='leaderstats'

    local Speed=Instance.new('IntValue',leaderstats)
    Speed.Name='Speed'
    Speed.Value=dataHandler.LoadData(Player).Speed or 5
    
    Speed.Changed:Connect(function()
        local DataCache=dataHandler.cache    
        if DataCache[Player.UserId] then 
            DataCache[Player.UserId].Speed=Speed.Value
        end
    end)
end)

Players.PlayerRemoving:Connect(function(Player)
    dataHandler.SaveData(Player)

end)```
rose oracle
#

backticks bruh `

karmic adder
rose oracle
#

also you didn't state a problem or ask a question. questions usually have a questionmark at the end

karmic adder
#

he is using the wrong one

swift viper
#

the data doesn't want to save, can anyone help? please

rose oracle
#

also just taking a wild guess here you have a problem with fetching the data because you fetch the data and then discard it, doing absolutely nothing with it ```lua
function module.LoadData(Player)

local Success, Data=pcall(function()
    return SpeedData:GetAsync(Player.UserId)
end)

cache[Player]=Player.leaderstats.Speed.Value
return cache[Player]

end```

karmic adder
#

thats part of a module?

swift viper
#

i send serverscript and a module of the server script

rose oracle
karmic adder
#

oh yeahhhh

#

wait whats he supposed to do

rose oracle
karmic adder
#

im SHIT at data

rose oracle
#

im not even looking at the datastore, i'm just looking at what happens to the return value of whatever:getasync

#

nothing happens to it 🪦

#

even if save worked properly, its not fetching properly so it doesnt matter. also doesnt matter if server script or module or whatever, since the return value of the getasync is discarded 💀

rose oracle
swift viper
#

    local Success, Data=pcall(function()
        return SpeedData:GetAsync(Player.UserId)
    end)

    cache[Player]=Data```
#

like this

karmic adder
rose oracle
# swift viper like this

this line of questioning is not productive. do some research, google, tutorials etc, read the docs, you got a long way to go salute

#

iteration is your friend. trial and error. but educated trial and error is better than blind trial and error salute

karmic adder
#

ty!

#

@rose oracle u got any documents or video explaining how to understand datamodules etc

rose oracle
#

not exaggerating either. i've mastered the datastore pattern and that's how i did it. goodluck salute

#

took me like 3 weeks of closely studying the docs and testing stuff