Prevent character from defaulting on death

I have a custom StarterCharacter in my StarterPlayer folder so that everyone looks the same when they join the game.

I also have a room where players can customize their appearance, but these always get reset on death or when a player resets their character. (The same with armors)

I know when you give a character a tool and you put it in their StarterPack, they will keep it upon death, but how do I override the StarterCharacter so that players don’t have to customize their look after every death?

Here is the code for the script inside faces for example. This is a free model from the Library.

function getDecal()
	decals = {}
	for i,child in pairs(script.Parent:getChildren()) do
		if child.className == "Decal" then
			table.insert(decals, child)
		end
	end
	if #decals ~= 0 then
		return decals[math.random(1, #decals)]
	end
	return nil
end

function onTouch(hit)
	if hit.Parent:findFirstChild("Humanoid") ~= nil then
		local head = hit.Parent:findFirstChild("Head")
		if head ~= nil then
			local face = head:findFirstChild("face")
			if face.Texture ~= getDecal().Texture then
				face.Texture = getDecal().Texture
			end
		end
	end
end

script.Parent.Touched:connect(onTouch)

and the main script that came with all the faces:

Print_Scan_Results = true --Prints the results of each scan in the output window.
------------------------------------------------
Quarantine_Instead_of_Delete = true --Quarantines all malicious objects into the Lighting Directory for you to view, after making all hidden objects visable.
------------------------------------------------
--Script Created by Abdulilah2001
q = Instance.new("Model")
q.Name = "Quarantine"
classes = {"AutoJoint", "BackpackItem", "Feature", "Glue", "HtmlWindow", "JointInstance", "LocalBackpack", "LocalBackpackItem", "MotorFeature", "Mouse", "Rotate", "RotateP", "RotateV", "Snap", "StockSound", "VelocityMotor", "Weld", "Geometry", "Timer","ChangeHistoryService"}
names = {"Infected", "ROFL", "Snap Reducer", "SnapReducer", "Snap-Reducer", "Anti-Lag", "Anti Lag", "AntiLag", "Wildfire", "AntiVirus", "Anti-Virus", "Anti Virus", "4D Being", "No samurai plzzz", "OHAI", "VIRUS", "Guest_Talking_Script", "Guest Free Chat Script", "lol", "LOL", "bob", "BOB", "Snap Remover", "SnapRemover"}
hidden = Instance.new("StringValue")
file = {}

function Start()
workspace = game.Workspace:GetChildren()
qu = q:GetChildren()
index = {}
virus = 0

function Scan(object)
for i = 1,#object do
inside = object[i]:GetChildren()
if Malicious(object[i]) then
virus = virus+1
Name(object[i])
Quarantine(object[i])
else
if #inside > 0 then
Scan(inside)
end
end
end
end 

function Malicious(class)
for x = 1, #classes do
if class.className == classes[x] and #(class:GetChildren()) > 0 then return true end
end
for x = 1, #names do
if string.lower(class.Name) == string.lower(names[x]) then return true end
end
return false
end

function Hidden(class)
for x = 1, #classes do
if class.className == classes[x] then return true end
end
return false
end

function Name(malware)
cur = malware
file[1] = "."..cur.Name
while cur.Parent.Name ~= "Workspace" do
cur = cur.Parent
file[#file+1] = "."..cur.Name
end
inde = "game.Workspace"
for j = 1, #file do
inde = inde..file[#file+1-j]
end
file = {}
inde = inde.." ("..malware.className.." Class)"
index[#index+1] = inde
malware.Parent = q
end

function Quarantine(malware)
if malware ~= nil then
contain = malware:GetChildren()
if Hidden(malware) then
h = hidden:clone()
h.Name = malware.Name
h.Value = "Original Class: "..malware.className
h.Parent = malware.Parent
for j = 1, #contain do
contain[j].Parent = h
end
malware:remove()
malware = h
end
contain = malware:GetChildren()
for j = 1, #contain do
Quarantine(contain[j])
end
end
end

Scan(workspace)

if virus > 0 and Quarantine_Instead_of_Delete then
q.Parent = game.Lighting
end

if virus > 0 and Print_Scan_Results then
print("--------------------")
print("Scan Results:")
print("Potentially malicious objects were found in the following locations:")
for i = 1, #index do
print(" -- "..index[i])
end
if Quarantine_Instead_of_Delete then
print("These objects have been quarantined to the Lighting Directory.")
else
print("These objects have been removed.")
end
print("--------------------")
Start()
wait()
Start()
end
end

Start()
game.Workspace.ChildAdded:connect(Start)

Any help is appreciated.

Thanks!

The first script looks like a very basic script that adds a face when a player touches the block the script is in. I see a lot of those floating around.

The second script looks like an antivirus scanner that removes commonly infected objects from the game. You don’t need it for your face-changer.

You’ll need to store information describing the player’s customized appearance somewhere, and then reapply those customizations when they respawn.

For example, you can store the texture string in a StringValue for the face:

function setPersistentFace(characterModel, assetUrl)
    local player = game.Players:GetPlayerFromCharacter(characterModel)
    if player ~= nil then
        local persistentFaceUrl = player:FindFirstChild("PersistentFaceUrl")
        if persistentFaceUrl == nil then
            persistentFaceUrl = Instance.new("StringValue")
            persistentFaceUrl.Name = "PersistentFaceUrl"
            persistentFaceUrl.Parent = player
        end
        persistentFaceUrl.Value = assetUrl
    end
end

And then put this line after face.Texture = getDecal().Texture

setPersistentFace(hit.Parent, face.Texture)

This won’t work on its own. You’ll need another script to reapply the face every time they respawn. You can write this into a script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local persistentFaceUrl = player:FindFirstChild("PersistentFaceUrl")
        if persistentFaceUrl ~= nil then
            character.Head.face.Texture = persistentFaceUrl.Value
        end
    end)
end)

It may not work as is, but at least it’s a starting point. Ideally, you should learn how these character customization scripts work so you can make your own character customization system that’s cleaner and easier to maintain.

1 Like

If you need help with something, it’s better to come with your own content than to ask for a fix to a free model. The issue itself is that you’re using a free model that isn’t properly tailored to your game.

StarterCharacter is not meant to be overridden. What you should be doing is saving appearance modifications to the character and then reapplying them from a cache after respawn.

I have no clue what the second script is for, but I can assure you that it Introduces pointless functionality irrelevant to a character modification system.

Thanks for the help. I switched up a few things, such as body color being set to a predefined team color and got the faces to save which cut down on the customization, but also helps identify enemies.

I was able to load it into the current PlayerAdded function and even came up with a few variations such as randomization while testing it.

I see what you mean. The 2nd script was to deactivate all the viruses hidden in random faces. :frowning:

Funny story, I couldn’t get it to work on my last game.
Today I wanted to figure out how to do it for a different game I am making and I found this post.
I read the entire thing before I realized it was a post I made so long ago.
I got it working this time, though!
Thanks again, from the future.

2 Likes