Hello, i tried to find a solution to this bug but i cant find what is the problem with my script. i even tried to copy other saving data scripts but it doesn’t work. The problem is basicly that the data is not saving or its doing it some times but i dont know why. it like saved the data 2-3 times then stopped working i hope i can find somone to help. thats my script.
`local serverstorage = game:GetService(“ServerStorage”)
local DataStore = game:GetService(“DataStoreService”):GetDataStore(“PlayerSave1”)
game.Players.PlayerAdded:Connect(function(Player)
local stats = Instance.new("Folder")
stats.Name = "Stats"
stats.Parent = Player
local rc = Instance.new("IntValue")
rc.Name = "RC"
rc.Parent = stats
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = stats
local SkillP = Instance.new("IntValue")
SkillP.Name = "SkillPoints"
SkillP.Parent = stats
local WeopenName = Instance.new("StringValue")
WeopenName.Name = "WeopenType"
WeopenName.Parent = stats
--------------- SprintValues ------------------------------------
local Staminafolder = Instance.new("Folder")
Staminafolder.Name = "SprintValues"
Staminafolder.Parent = stats
local maxStamina = Instance.new("IntValue", Staminafolder)
maxStamina.Value = 300
maxStamina.Name = "maxStamina"
local stamina = Instance.new("IntValue", Staminafolder)
stamina.Value = maxStamina.Value
stamina.Name = "Stamina"
local staminaRegen = Instance.new("IntValue", Staminafolder)
staminaRegen.Value = 1
staminaRegen.Name = "staminaRegen"
local sprintModifier = Instance.new("NumberValue", Staminafolder)
sprintModifier.Value = 1.5
sprintModifier.Name = "sprintModifier"
local sprintStaminaCost = Instance.new("IntValue", Staminafolder)
sprintStaminaCost.Value = 1
sprintStaminaCost.Name = "sprintStaminaCost"
-------------------------------------------------------------------------------------------------------------------------
local DataFolder = Instance.new("Folder")
DataFolder.Name = Player.Name
DataFolder.Parent = serverstorage.RemoteData
-- data save
local RCdata, Cashdata, SkillPdata, WeopenNameData, maxStaminaData, sprintModifierData
local success, errormessage = pcall(function()
RCdata = DataStore:GetAsync("RC-"..Player.UserId)
Cashdata = DataStore:GetAsync("Cash-"..Player.UserId)
SkillPdata = DataStore:GetAsync("SkillPoints-"..Player.UserId)
WeopenNameData = DataStore:GetAsync("WeopenType-"..Player.UserId)
maxStaminaData = DataStore:GetAsync("MaxStamina-"..Player.UserId)
sprintModifierData = DataStore:GetAsync("sprintModifier-"..Player.UserId)
end)
if success then
rc.Value = RCdata
cash.Value = Cashdata
SkillP.Value = SkillPdata
WeopenName.Value = WeopenNameData
maxStamina.Value = maxStaminaData
sprintModifier.Value = sprintModifierData
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
DataStore:SetAsync(“RC-”…player.UserId,player.Stats.RC.Value)
DataStore:SetAsync(“Cash-”…player.UserId,player.Stats.Cash.Value)
DataStore:SetAsync(“SkillPoints-”…player.UserId,player.Stats.SkillPoints.Value)
DataStore:SetAsync(“WeopenType-”…player.UserId,player.Stats.WeopenType.Value)
DataStore:SetAsync(“MaxStamina-”…player.UserId,player.Stats.SprintValues.maxStamina.Value)
DataStore:SetAsync(“sprintModifier-”…player.UserId,player.Stats.SprintValues.sprintModifier.Value)
end)
end)`