I have a menu which changes the players appearance.
I want my character to spawn with the last appearance it had on reset and when he rejoins game.
I have two folders on for Level and Money The other for Shirt , Pants , Hat , Hair , Face , Skin
How would I link a shirt img to a value
not sure if that's the exact question but hopefully someone can understand what I'm saying
Take look at what I came up , new to coding with datastore so please please please help me out .
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")
local function onPlayerJoin(player)
print("please wait!")
wait(3)
print("STARTING!")
--------------------------------------------------------------------------------------------------------------------------------
local leaderstats = Instance.new("Folder") --Sets up leaderstats folder
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
---------------------------------------------------------------------------------------------------------------------------------
local Shards = Instance.new("IntValue") --Sets up value for leaderstats
Shards.Name = "Shards"
Shards.Parent = leaderstats
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = leaderstats
---------------------------------------------------------------------------------------------------------------------------------
local CharStats = Instance.new("Folder") --Sets up leaderstats folder
CharStats.Name = "CharStats"
CharStats.Parent = player
----------------------------------------------------------------------------------------------------------------------------------
local Shirt= Instance.new("IntValue") --Sets up value for leaderstats
Shirt.Name = "Shirt"
Shirt.Parent = CharStats
local Pants= Instance.new("IntValue")
Pants.Name = "Pants"
Pants.Parent = CharStats
local Face= Instance.new("IntValue")
Face.Name = "Face"
Face.Parent = CharStats
local Hat= Instance.new("IntValue")
Hat.Name = "Hat"
Hat.Parent = CharStats
local Hair= Instance.new("IntValue")
Hair.Name = "Hair"
Hair.Parent = CharStats
local Skin= Instance.new("IntValue")
Skin.Name = "Skin"
Skin.Parent = CharStats
----------------------------------------------------------------------------------------------------------------------------------------------
local playerUserId = "Player_" .. player.UserId --Gets player ID
local data = playerData:GetAsync(playerUserId) --Checks if player has stored data
if data then
Shards.Value = data['Shards']
Level.Value = data['Level']
Shirt.Value = data['Shirt']
Pants.Value = data ['Pants']
Face.Value = data ['Face']
Hair.Value = data['Hair']
Hat.Value = data['Hat']
Skin.Value = data['Skin']
else
---------------------------------------------Data store is working, but no current data for this player------------------------
Shards.Value = 0
Level.Value = 1
Shirt.Value = 1
Pants.Value = 1
Face.Value = 1
Hair.Value = 1
Hat.Value = 1
Skin.Value = 1
end
end
-----------------------------------------------------------------------------------------------------------------------------------
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player.leaderstats:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
----------------------------------------------------------------------------------------------------------------------------------------
local function onPlayerExit(player) --Runs when players exit
local player_stats = create_table(player)
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player_stats) --Saves player data
end)
if not success then
warn('Could not save data!')
end
end
--------------------------------------------------------------------------------------
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)

2 comments
You can try saving the Shirt ID, and the accesory asset ID
@marijus06 how would I do this exactly?