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)
There is this cool little thing here called HumanoidDescription. It can be used to apply hats, limb colors, accessory, clothing, etc. What we could do is save it to the datastore with Players:GetHumanoidDescriptionFromUserId
, and use the player:LoadCharacterWithHumanoidDescription(humanoidDescription)
to load it in with the humanoid description. Here is ur script:
local dss = game:GetService("DataStoreService") local http = game:GetService("HttpService") local playerData = dss:GetDataStore("playerData") game.Players.PlayerAdded:Connect(function(player) local lead = Instance.new("Folder",player) lead.Name = "leaderstats" local shards = Instance.new("IntValue",lead) shards.Name = "Shards" local level = Instance.new("IntValue",lead) level.Name = "Level" local data local suc, err = pcall(function() data = http:JSONDecode(playerData:GetAsync(player.UserId)) end) if suc then if data then player.leaderstats.Shards.Value = data.shards player.leaderstats.Level.Value = data.level player:LoadCharacterWithHumanoidDescription(data.humDescription) -- load it with the description else player.leaderstats.Shards.Value = 0 -- ur default value player.leaderstats.Level.Value = 0 -- same here end else warn(err) end end) game.Players.PlayerRemoving:Connect(function(player) local data = { shards = player.leaderstats.Shards.Value, level = player.leaderstats.Level.Value, humDescription = game.Players:GetHumanoidDescriptionFromUserId(player.UserId) -- save the description } playerData:SetAsync(http:JSONEncode(data)) end)
Hope you understood it!