Hello devs! I am working on skin system for my game using StringValues and wanted this Value to save, when i tried DataStore StringValue, it showed, only IntValues can be saved. Here is my code :
local DataStore = game:GetService("DataStoreService")
local Data1 = DataStore:GetDataStore("Data1")
game.Players.PlayerAdded:Connect(function(player)
local Data
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = player
local Survivals = Instance.new("IntValue")
Survivals.Name = "Survivals"
Survivals.Parent = stats
local Died = Instance.new("BoolValue")
Died.Name = "HasDied"
Died.Parent = player
local Died = Instance.new("BoolValue")
Died.Name = "IsRake"
Died.Parent = player
local Skin = Instance.new("StringValue")
Skin.Name = "Skin"
Skin.Parent = player
Skin.Value = "Rake"
local Points = Instance.new("IntValue")
Points.Name = "Points"
Points.Parent = stats
wait(0.1)
local playerUserId = "Player_"..player.UserId
local succes, errormessage = pcall(function()
Data = Data1:GetAsync(playerUserId)
end)
if succes then
Survivals.Value = Data.Survivals
end
game.ReplicatedStorage.PlayersInGame.Value = game.ReplicatedStorage.PlayersInGame.Value + 1
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local Data = {
Survivals = player.leaderstats.Survivals.Value
}
local succes, errormessage = pcall(function()
Data1:SetAsync(playerUserId, Data)
end)
if succes then
print("Data saved succesfuly!")
else
warn(errormessage)
end
game.ReplicatedStorage.PlayersInGame.Value = game.ReplicatedStorage.PlayersInGame.Value - 1
end)