Not sure what this error means?

Just trying to make a script to remove players hats upon joining. And also, my character has an invisible head “hat” which creates a special mesh it seems and I need to change that mesh back to default block head mesh. But I get this error (below)

game.Players.PlayerAdded:Connect(function(player)
	local function removeHats(character)
		for _, child in ipairs(character:GetChildren()) do
			if child:IsA("Accessory") then
				child:Destroy()
			end
			if child.Name == "Head" then
				child.MeshId = "https://assetdelivery.roblox.com/v1/asset/?id=7430070993"
			end
		end
	end

	player.CharacterAppearanceLoaded:Connect(function(character)
		removeHats(character)
	end)

	-- Handle case when player character changes
	player.CharacterAdded:Connect(function(character)
		removeHats(character)
	end)
end)

Error:

 The current thread cannot write 'MeshId' (lacking capability NotAccessible)  -  Server - Script:8
  19:18:29.597  Stack Begin  -  Studio
  19:18:29.597  Script 'ServerScriptService.Script', Line 8 - function removeHats  -  Studio - Script:8
  19:18:29.597  Script 'ServerScriptService.Script', Line 14  -  Studio - Script:14
  19:18:29.597  Stack End  -  Studio

The error if I remember correct is as stated that you can’t write over the propery, Its not Accessible, and Viewing this on the roblox docs page provides this info:


“Attemping to access this member in scripts causes an error”.

which relates to this line here child.MeshId = "https://assetdelivery.roblox.com/v1/asset/?id=7430070993"

which might explain the error to you. You can only use special Meshing for what your trying to do I think.

2 Likes

How can I change the head mesh then? I’ve tried importing a special mesh into the head part and it does nothing.

I haven’t messed with Meshes too much. All I know is that you need to use a special Mesh, But Roblox does have Doc page for this that after reading it might help you on how to use it in your case?

Hey @matt1020304050! I tried to edit your script, and I think this would work:

game.Players.PlayerAdded:Connect(function(player)
    local function removeHats(character)
        for _, child in ipairs(character:GetChildren()) do
            if child:IsA("Accessory") then
                child:Destroy()
            end
            if child.Name == "Head" then
                local originalHead = game.ReplicatedStorage.DefaultHead
                local headMesh = child:FindFirstChild("Mesh")
                if headMesh then
                    headMesh.MeshId = originalHead.MeshId
                end
            end
        end
    end

    player.CharacterAppearanceLoaded:Connect(function(character)
        removeHats(character)
    end)

    player.CharacterAdded:Connect(function(character)
        removeHats(character)
    end)
end)

Also, keep in mind that I am not a scripting expert, so if it doesn’t work, please don’t be mad at me. At least I tried. By the way, nice dominus. :wink:
If you found my answer useful, do not forget to mark it as solved :white_check_mark:.
@Katastro5 :cool:

There’s already a topic which solved this problem:

It uses a little bit different of a system.

Ummmm asset delivery might not work for that because it contains file data not roblox mesh data I think so just try

rbxassetId://7430070993

The problem is, is that I can’t assign the mesh in the first place. Thanks though

Adding a special mesh does nothing :confused: