Instance not being destroyed

Im trying to destroy a model after all the parts in the shape’s activated value is true, but for some reason it does not work

its probably gonna be a dumb problem with an easy fix

here is the code:

local cutter  = game.Workspace.cutter

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local HRP = player.Character:WaitForChild("HumanoidRootPart")

local Mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")

local shapeParts = game.Workspace.Shape:GetChildren()
local shape = game.Workspace.Shape

local isMouse_HELD = false

game:GetService("RunService").RenderStepped:Connect(function()
	cutter.Position = Vector3.new(Mouse.Hit.X, Mouse.Hit.Y , Mouse.Hit.Z)
end)

Mouse.TargetFilter = cutter

UIS.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.MouseButton1 and Mouse.Target:IsA("Part") and Mouse.Target.Name == "cuttablePart" then
			
			Mouse.Target.BrickColor = BrickColor.new("Sage green")
			Mouse.Target.Activated.Value = true
			
			for _, activatedParts in pairs(shapeParts ) do
				if activatedParts.Activated == true then
					shape:Destroy()
				end
			end
			
		elseif Mouse.Target.Name == "uncuttablePart" then
			Mouse.Target.Value.Value += 1
			Mouse.Target.BrickColor = BrickColor.new("Really red")
			
			if Mouse.Target.Value.Value >= 5 then
				player.Character.Humanoid.Health = 0
				
			end
		end
	end
end)

as far as server replication goes, im intentionally loading everything on the client to prevent other players sabotaging you

I tried your fix, but it does not seem to work

1 Like

They are just parts, and I did print them, it all seems to work

Could you show me which printed and what did it print? and is Activated a part as well?

I’m not sure if this will work but more or less this should print out something to tell you where your script stops and the error began.

Right at the top of the script “Local players”.

if activatedParts.Activated.Value == true then
end

This previously found change is necessary also.

local cutter  = game.Workspace.cutter
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local HRP = player.Character:WaitForChild("HumanoidRootPart")
local Mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local shapeParts = game.Workspace.Shape:GetChildren()
local shape = game.Workspace.Shape
local isMouse_HELD = false

game:GetService("RunService").RenderStepped:Connect(function()
	cutter.Position = Vector3.new(Mouse.Hit.X, Mouse.Hit.Y , Mouse.Hit.Z)
end)
Mouse.TargetFilter = cutter

UIS.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.MouseButton1 and Mouse.Target:IsA("Part") and Mouse.Target.Name == "cuttablePart" then
			Mouse.Target.BrickColor = BrickColor.new("Sage green")
			Mouse.Target.Activated.Value = true
			for _, activatedParts in pairs(shapeParts) do
				if activatedParts.Activated.Value then
					shape:Destroy()
				end
			end
		elseif Mouse.Target.Name == "uncuttablePart" then
			Mouse.Target.Value.Value += 1
			Mouse.Target.BrickColor = BrickColor.new("Really red")
			if Mouse.Target.Value.Value >= 5 then
				player.Character.Humanoid.Health = 0
			end
		end
	end
end)

This won’t work but everything looks fine, probably some issue with your references to external instances.