Why is this character saving script not saving?

I’ve been working on a pretty good character creation thing for the last two days and it works perfectly up until it has to save right here:

if game.Workspace.Dummy:FindFirstChild("Hair") then
			local hairr = game.Workspace.Dummy.Hair:FindFirstChild("Handle")
			if hairr:FindFirstChild("Mesh") or hairr:FindFirstChild("SpecialMesh") then
				if hairr:FindFirstChild("Mesh").MeshId == "http://www.roblox.com/asset/?id=16627529" then
					har:SetAsync(plr.UserId, 1)
				elseif hairr:FindFirstChild("Mesh").MeshId == "http://www.roblox.com/asset/?id=13070796" then
					har:SetAsync(plr.UserId, 2)
				elseif hairr:FindFirstChild("Mesh").MeshId == "rbxassetid://4723908785" then
					har:SetAsync(plr.UserId, 3)
				elseif hairr:FindFirstChild("SpecialMesh").MeshId == "rbxassetid://4660065409" then
					har:SetAsync(plr.UserId, 4)
				end
				if game.Workspace.Dummy.Hair.Handle.Color == Color3.fromRGB(24, 24, 24) then
					hairColor:SetAsync(plr.UserId, 1)
				elseif game.Workspace.Dummy.Handle.Hair.Color == Color3.fromRGB(199, 151, 102) then
					hairColor:SetAsync(plr.UserId, 2)
				elseif game.Workspace.Dummy.Handle.Hair.Color == Color3.fromRGB(86, 58, 35) then
					hairColor:SetAsync(plr.UserId, 3)
				end
			end
		else
			wait()
		end

it says im trying to index nil with meshid…

Any ideas why?

It’s saying that

hairr:FindFirstChild("Mesh")

or (give full error message please)

hairr:FindFirstChild("SpecialMesh")

is nil.
This is a flaw in your if statement, you’re checking if either “Mesh” or “SpecialMesh” exist, what if one of them existed and one didn’t, the next if statements would be checking for the one that didn’t exist anyways.
Do this instead.

		if hairr:FindFirstChild("Mesh") then
				if hairr:FindFirstChild("Mesh").MeshId == "http://www.roblox.com/asset/?id=16627529" then
					har:SetAsync(plr.UserId, 1)
				elseif hairr:FindFirstChild("Mesh").MeshId == "http://www.roblox.com/asset/?id=13070796" then
					har:SetAsync(plr.UserId, 2)
				elseif hairr:FindFirstChild("Mesh").MeshId == "rbxassetid://4723908785" then
					har:SetAsync(plr.UserId, 3)
        elseif hairr:FindFirstChild("SpecialMesh") then
				elseif hairr:FindFirstChild("SpecialMesh").MeshId == "rbxassetid://4660065409" then
					har:SetAsync(plr.UserId, 4)
				end
        end

Checking each type of mesh seperately, it might also be a good idea to organize your code a bit.

2 Likes

it looks like this now but still does not work

if game.Workspace.Dummy:FindFirstChild("Hair") then
			local hairr = game.Workspace.Dummy.Hair:FindFirstChild("Handle")
			if hairr:FindFirstChild("Mesh") then
				if hairr.Mesh.MeshId == "http://www.roblox.com/asset/?id=16627529" then
					har:SetAsync(plr.UserId, 1)
				elseif hairr.Mesh.MeshId == "http://www.roblox.com/asset/?id=13070796" then
					har:SetAsync(plr.UserId, 2)
				elseif hairr.Mesh.MeshId == "rbxassetid://4723908785" then
					har:SetAsync(plr.UserId, 3)
       		elseif hairr:FindFirstChild("SpecialMesh") then
				elseif hairr.SpecialMesh.MeshId == "rbxassetid://4660065409" then
					har:SetAsync(plr.UserId, 4)
				end

What is the error you’re getting?

1 Like

just a whole bunch of

15:10:47.650 - Script timeout: exhausted allowed execution time

15:10:47.651 - Stack Begin

15:10:47.652 - Script ‘ServerScriptService.MainServer.ServerError’, Line 5

15:10:47.653 - Stack End

ill check in game what it says

EDIT: it looks like its working now but ill make sure

1 Like