#Data save problem
1 messages · Page 1 of 1 (latest)
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
Any errors
?
Yes
** You are now Level 11! **
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)
print bag_20 and savedbag on playeradded and bag_20.Value on removal
i think i know problemm , the problem bec the value that change to 1 in local script
right ?
Wait
DataStoreService can only be used in Server Scripts
but he didn't mention it being local script tho-
he did, here
yeah i did it late sorry
ok so i do remote event ?
oh-
no just move that script to a server script
but like this of someone buy the gear all servers will have it too
If you don't know how DataStores work, go read the DataStores documentation or watch some youtube tutorial
ok ty