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:
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. If you found my answer useful, do not forget to mark it as solved . @Katastro5