I have a script made to change a crystal heart mesh when a variable changes, the crystal is in a viewport frame but I'm getting errors of the mesh id being read-only, can I have some sort of explanation?

script

--services
local Players = game:GetService("Players")
--player
local Player = Players.LocalPlayer --player instance
--modules

--Vars
local Health = Player.Health --serversided variablein player instance
--Tables
local HeartMesh = {
	[5] = 'rbxassetid://5547057733',
	[4] = 'rbxassetid://5547072348',
	[3] = 'rbxassetid://5547077961',
	[2] = 'rbxassetid://5547081191',
	[1] = 'rbxassetid://5547083819'
}
--objects
local HeartFrame = script.Parent:WaitForChild("HeartFrame") --Viewport frame where the heart object is
local Heart = HeartFrame:WaitForChild('Heart') --Heart mesh object in Viewport frame
--functions
Health.Changed:Connect(function()-- Change MeshId depending on damage
	if Health.Value > 0 then
		Heart.MeshId = HeartMesh[Health.Value]
		Heart.Transparency = 0.5
	else
		Heart.Transparency = 1
	end
end)
--Startup

2 comments

0

script was simplified as the other bits of code don't contribute to the question

0

Health.Value is aways a value from 0 to 5?