#Data save problem

1 messages · Page 1 of 1 (latest)

small sorrel
#

I do bag system that if int_value is = 1 and u have 50 coins u unlock the new bag , and if int_value = 0 so u dont have money to buy it , problem here that my script doesnt save int_value

#
local DataStoreService = game:GetService("DataStoreService")
local bagdata = DataStoreService:GetDataStore("bagdata")

game.Players.PlayerAdded:Connect(function(plr)
    local bag_20 = game.ReplicatedStorage.Bags_check.Bag_20
    
    local success , savedbag  = pcall(function()
        return bagdata:GetAsync(plr.UserId)
    end)
    
    if success and savedbag then
        bag_20.Value = savedbag
    end
end)

game.Players.PlayerRemoving:Connect(function(plr_leave)
    local bag_20 = game.ReplicatedStorage.Bags_check.Bag_20
    pcall(function()
        bagdata:SetAsync(plr_leave.UserId , bag_20.Value)
    end)
end)
#

here is script

small sorrel
#

nope

#

i change it

#

can i show u my new script

tardy ice
#

Yes

jagged patioBOT
#

studio** You are now Level 11! **studio

small sorrel
#
local DataStoreService = game:GetService("DataStoreService")
local bagdata = DataStoreService:GetDataStore("bagdata")

game.Players.PlayerAdded:Connect(function(plr)
    local bag_20 = Instance.new("IntValue" , plr)
    bag_20.Name = "Bag_20"
    bag_20.Value = 0
    
    
    
    local success , savedbag  = pcall(function()
        return bagdata:GetAsync(plr.UserId)
    end)
    
    if success and savedbag then
        bag_20.Value = savedbag
    end
end)

game.Players.PlayerRemoving:Connect(function(plr_leave)
    local bag_20 = plr_leave:WaitForChild("Bag_20")
    pcall(function()
        bagdata:SetAsync(plr_leave.UserId , bag_20.Value)
    end)
end)
tardy ice
#

Read the docs

tidal void
small sorrel
#

right ?

tidal void
#

DataStoreService can only be used in Server Scripts

tardy ice
#

You have this in a local script?

#

Lol

strong pollen
#

but he didn't mention it being local script tho-

small sorrel
#

ok so i do remote event ?

strong pollen
#

oh-

tidal void
small sorrel
tidal void
small sorrel
#

ok ty