How do I make a skin finder thing?

So, I want to make it so it tracks the player’s character and skin but i have no idea how to. All i’ve seen were making it the StarterCharacter but that’s not what I’m looking for. For reference, a game like Phighting, or Forsaken. How do they achieve this?

local repStorage = game:GetService("ReplicatedStorage")

local function attachHitboxToPlayer(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local hrp = character:WaitForChild("HumanoidRootPart")

	local hitbox = Instance.new("Part")
	hitbox.Name = "PlayerHitbox"
	hitbox.Size = Vector3.new(4, 6, 4)
	hitbox.Transparency = 1
	hitbox.CanCollide = false
	hitbox.Anchored = false
	hitbox.Massless = true
	hitbox.Parent = character
	hitbox.Color = Color3.fromRGB(255, 0, 0)

	hitbox.CFrame = hrp.CFrame

	local weld = Instance.new("WeldConstraint")
	weld.Part0 = hrp
	weld.Part1 = hitbox
	weld.Parent = hitbox
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Wait()

	local statFolder = Instance.new("Folder")
	statFolder.Name = "leaderstats"
	statFolder.Parent = player

	local side = Instance.new("StringValue")
	side.Name = "Side"
	side.Value = "Classic"
	side.Parent = statFolder

	local character = Instance.new("StringValue")
	character.Name = "Character"
	character.Value = "Noob"
	character.Parent = statFolder
	
	local skin = Instance.new("StringValue")
	skin.Name = "Skin"
	skin.Value = "Default"
	skin.Parent = character
	
	attachHitboxToPlayer(player)
	player.Character = repStorage.Players.Characters[side.Value][character.Value].Skins[skin.Value]
end)
1 Like

edit note: i was too tired to realize there was more of the code snippet to read … sorry

what I would do is use datastore2 to save the name of the character model you want to save like so:

local players = game:GetService("Players");
local dataStore2 = require(...);

dataStore2.combine("MAIN", "Character");

local function PlayerAdded(player: Player)
    local values = Instance.new("Folder");
    values.Name = "Values";
    values.Parent = player;

    local characterValue = Instance.new("StringValue");
    characterValue.Name = "Character";
    characterValue.Parent = values;

    local characterStore = dataStore2("Character", player);
    local savedCharacter = characterStore:Get(DEFAULT_CHARACTER_NAME_HERE);

    characterValue.Value = savedCharacter;   
end

players.PlayerAdded:Connect(PlayerAdded);

for getting and loading characters:

local values = player:FindFirstChild("Values");
local characterValue = values:FindFirstChild("Character");

local characterModel = ...:FindFirstChild(characterValue.Value);

player.Character = characterModel;

with the image you provided there seems to also include other stuff like animations, skins and etc so I don’t really know how you would optimize the idea to work with that but it’s a good start

1 Like
    player.CharacterAdded:Wait()

	local statFolder = Instance.new("Folder")
	statFolder.Name = "leaderstats"
	statFolder.Parent = player

	local side = Instance.new("StringValue")
	side.Name = "Side"
	side.Value = "Classic"
	side.Parent = statFolder

	local character = Instance.new("StringValue")
	character.Name = "Character"
	character.Value = "Noob"
	character.Parent = statFolder
	
	local skin = Instance.new("StringValue")
	skin.Name = "Skin"
	skin.Value = "Default"
	skin.Parent = character

and also, why wait for the character to be added before creating values that the player should only have once

1 Like

one more thing to consider is that you should probably also put things that only the server will usually access in serverstorage or serverscriptstorage, it’s a good way to protect your game from exploits that attempt decompilation and it probably gives the client less things to load