Unable to assign property MeshId. Script write access is restricted

I’ve made a script which shoots out stars and assign a meshpart which makes them change the meshpart’s id but it outputs in the error.

Unable to assign property MeshId. Script write access is restricted

At line 21

My code is :

local debounce = false
MouseLoc = script.Parent:WaitForChild("MouseLoc")

script.Parent.Activated:Connect(function()
	local character = script.Parent.Parent
	local targetPos = MouseLoc:InvokeClient(game:GetService("Players"):GetPlayerFromCharacter(character))
	local lookAt = (targetPos - character.Head.Position).unit
	local star = Instance.new("MeshPart")
	local starmesh = game.ServerStorage.Starmesh:Clone()
	local dmg = game.ServerStorage.StarDamage:Clone()
	local destroy = game.ServerStorage.StarDestroy:Clone()
	local r = math.random(1,255)
	local g = math.random(1,255)
	local b = math.random(1,255)
	
	--debounce WOOOOOOOO
	if not debounce then
		debounce = true
		star.Color = Color3.fromRGB(r, g, b)
		star.Material = "Neon"
		star.MeshId = "545480491"
		star.Anchored = false
		star.CanCollide = false
		star.Size = Vector3.new("6.282, 4.257, 5.835")

		local spawnPos = script.Parent.Handle.Position
		spawnPos  = spawnPos + (lookAt * 5)

		star.Name = "SoulSwordStar"

		local antiGravity = Instance.new("BodyForce")
		antiGravity.Force = Vector3.new(0, workspace.Gravity * star:GetMass(), 0)
		antiGravity.Parent = star
		star.Velocity = lookAt  * 100
		
		destroy.Parent = star
		dmg.Parent = star
		starmesh.Parent = star
		star.Parent = workspace
		star:SetNetworkOwner((game:GetService("Players"):GetPlayerFromCharacter(character)))
		game:GetService("Debris"):AddItem(star, 10)
		star.Position = script.Parent.Parent.HumanoidRootPart.Position
		wait(0.75)
		debounce = false
	end
end)

Help would be appreciated thank you!

You can’t change MeshPart.meshID during runtime. You can only create:
2+ meshes with needed ID’s
And then delete unneeded mesh and replace it with clone of needed one.

Or you could use a standard BasePart instance with a SpecialMesh inside, their ‘MeshId’ property can be changed during runtime.