[Paying] Record player Character name when leaving, and when joining check that previous name?

Hey, I need a solution.

  • make it so every 15 seconds or so your Character models .Name is saved into a datastore.
  • when you join the game it checks the data store to see what that name is and executes some code.

I’ve tried numerous times. It never works??
I will pay 1000 Robux for the solution.

1 Like
  1. I do not need payment.
  2. This is just an example, and you will need to adjust the script variables.
  3. Instructions are in the script, you will need some basic understanding of where to put stuff.
  4. 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)
1 Like