This is just an example, and you will need to adjust the script variables.
Instructions are in the script, you will need some basic understanding of where to put stuff.
If the script doesn’t work, then you’re doing something wrong.
local DataStore = game:GetService("DataStoreService"):GetDataStore("CustomCharacterNameKey-1");
local SaveEvent = game.ReplicatedStorage:WaitForChild("customCharacterSave"); -- Create a RemoteEvent in ReplicatedStorage.
local TriggerClient = game.ReplicatedStorage:WaitForChild("customCharacterSaveClient"); -- Create RemoteEvent in ReplicatedStorage.
local CustomCharacters = game:GetService("ServerStorage"):WaitForChild("CustomCharacters"); -- Custom Characters Storage Location
local function CustomCharacterHandler(player,name,mode)
local CharactersInventory = player:FindFirstChild("Characters");
if mode == "save" then
if CustomCharacters:FindFirstChild(name) and CharactersInventory:FindFirstChild(name) then
local success,errormsg = pcall(function()
DataStore:SetAsync(player.UserId,name);
end);
if not success then
warn("Error: Custom Character Not Saved ("..player.Name..")");
end;
end;
elseif mode == "get" then
local characterName
local success,errormsg = pcall(function()
characterName = DataStore:GetAsync(player.UserId);
end);
if success then
if not CharactersInventory:FindFirstChild(characterName) then
DataStore:RemoveAsync(player.UserId);
return;
end;
local SavedCharacter = CustomCharacters:FindFirstChild(characterName);
if SavedCharacter then
-- "Executes some code"
end;
end;
end;
end;
SaveEvent.OnServerEvent:Connect(function(player,name,mode) -- LocalScript example (saving only): Event:FireServer("Bob","save")
if mode == "save" then
CustomCharacterHandler(player,name,mode);
end;
end);
game.Players.PlayerAdded:Connect(function(player)
CustomCharacterHandler(player,nil,"get");
end);
game.Players.PlayerRemoving:Connect(function(player)
TriggerClient:FireClient(player);
end)