#My database isn't using the values I set

15 messages · Page 1 of 1 (latest)

marsh citrus
#
local CoinsStore = DataStoreService:GetDataStore("CoinsStore")
local SpeedStore = DataStoreService:GetDataStore("SpeedStore")
local CostStore = DataStoreService:GetDataStore("CostStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    
    local Coins = Instance.new("IntValue")
    Coins.Name = "Coins"
    Coins.Parent = leaderstats
    

    local Speed = Instance.new("IntValue")
    Speed.Name = "Speed"
    Speed.Value = 1
    Speed.Parent = leaderstats
    
    local Cost = Instance.new("IntValue")
    Cost.Name = "Cost"
    Cost.Value = 20
    Cost.Parent = leaderstats
    
    local UserId = player.UserId
    
    local data
    
    local success, errormessage = pcall(function()
        data = CoinsStore:GetAsync(UserId)
        data = SpeedStore:GetAsync(UserId)
        data = CostStore:GetAsync(UserId)
    end)
    
    if success then
        Coins.Value = data
        Speed.Value = data
        Cost.Value = data
    else
        print("There was an error whilst getting your data")
        warn(errormessage)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local UserId = player.UserId
    local data = player.leaderstats.Coins.Value
    local data = player.leaderstats.Speed.Value
    local data = player.leaderstats.Cost.Value
    
    CoinsStore:SetAsync(UserId, data)
    SpeedStore:SetAsync(UserId, data)
    CostStore:SetAsync(UserId, data)
end)```
#

It's also not saving the values anymore

vale agate
#

u should use profile service as ur data

#

Since is the best data currently

marsh citrus
#

And how would i do that

vale agate
#

the code has like 2400 lines

marsh citrus
#

And this goes in the serverscriptservice right?

#

Also that's a lot of code

#

What lines would I have to change

vale agate
#

and put it in

#

sss

#

serverscriptservice

marsh citrus
#

Alright but what lines do i change to save a speed and a coins value?