i have a leaderstat and datastore script and 3 of the intvalue leaderstats work for saving but not the stringvalue stat, am i doing something wrong:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local dataStore = DataStoreService:GetDataStore("PlayerStats")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local speed = leaderstats:WaitForChild("Speed")
local strength = leaderstats:WaitForChild("Strength")
local endurance = leaderstats:WaitForChild("Endurance")
local aura = leaderstats:WaitForChild("Aura")
local data
local success, err = pcall(function()
data = dataStore:GetAsync(player.UserId)
end)
if success and data then
speed.Value = data.Speed or 16
strength.Value = data.Strength or 0
endurance.Value = data.Endurance or 0
aura.Value = data.aura or "None"
end
end)
Players.PlayerRemoving:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local speed = leaderstats:FindFirstChild("Speed")
local strength = leaderstats:FindFirstChild("Strength")
local endurance = leaderstats:WaitForChild("Endurance")
local aura = leaderstats:WaitForChild("Aura")
local data = {
Speed = speed and speed.Value or 16,
Strength = strength and strength.Value or 0,
Endurance = endurance and endurance.Value or 0,
Aura = aura and aura.Value or "None"
}
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, data)
end)
if not success then
warn("Failed to save data for player " .. player.Name .. ": " .. err)
end
end
end)
game:BindToClose(function()
for _, player in pairs(Players:GetPlayers()) do
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local speed = leaderstats:FindFirstChild("Speed")
local strength = leaderstats:FindFirstChild("Strength")
local endurance = leaderstats:FindFirstChild("Endurance")
local aura = leaderstats:WaitForChild("Aura")
local data = {
Speed = speed and speed.Value or 16,
Strength = strength and strength.Value or 0,
Endurance = endurance and endurance.Value or 0,
Aura = aura and aura.Value or "None"
}
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, data)
end)
if not success then
warn("Failed to save data for player " .. player.Name .. ": " .. err)
end
end
end
end)