How to fix camera hitbox plugin

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A nice hitbox for the camera!

  2. What is the issue? Include screenshots / videos if possible!
    ERROR ERROR ERROR ERROR (it spams parent locked errors at me - line 52 error - please dont steal this)

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    none

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local IsActive = false
local UseSquareHitbox = false

local Toolbar = plugin:CreateToolbar("Camera Physics (Run Mode Only)")

local Active = Toolbar:CreateButton(
	"Active",
	"Enables/Disables the camera hitbox.",
	"rbxassetid://17152447927"
)

Active.Click:Connect(function()
	if IsActive == false then
		IsActive = true
	else
		IsActive = false
	end
end)

local SquareMode = Toolbar:CreateButton(
	"Square",
	"Makes the camera hitbox a square, which will not rotate. Great for pushing parts such as dominoes.",
	"rbxassetid://17152521948"
)

SquareMode.Click:Connect(function()
	if UseSquareHitbox == false then
		UseSquareHitbox = true
	else
		UseSquareHitbox = false
	end
end)

-----

local CameraSphere = Instance.new("Part")
game["Run Service"].Stepped:Connect(function()
	if UseSquareHitbox == false then
		CameraSphere.Shape = "Ball"
	else
		CameraSphere.Shape = "Block"
	end
	CameraSphere.Transparency = 1
	CameraSphere.CanCollide = true
	CameraSphere.CastShadow = false
	CameraSphere.Size = Vector3.new(5, 5, 5)
	CameraSphere.Anchored = true
	CameraSphere.Name = "Physics"
	if CameraSphere and CameraSphere.Parent ~= nil then
		if IsActive == true then
			if 	CameraSphere.Parent ~= workspace then
				CameraSphere.Parent = workspace
			end
		else
			if 	CameraSphere.Parent ~= game.ServerStorage then
				CameraSphere.Parent = game.ServerStorage
			end
		end
	end
	CameraSphere:PivotTo(workspace.Camera.CFrame)
	if UseSquareHitbox == true then
		CameraSphere.Orientation = Vector3.new(0, 0, 0)
	end
	for i, obj in pairs(workspace:GetDescendants()) do
		if obj and obj:FindFirstChildOfClass("Humanoid") and obj:FindFirstChild("Head") and obj:FindFirstChild("HumanoidRootPart") and obj:FindFirstChild("Head"):FindFirstChild("face") then
			if CameraSphere and CameraSphere:IsA("Part") then
				CameraSphere:Destroy()
			end
		end
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

just wrap the line that errors in a pcall :100:

but for real it errors because youre destroying the hitbox on line 67 in a weird loop

can you wrap it in a pcall? idk pcalls

its not really efficient to use pcalls but here you go

local IsActive = false
local UseSquareHitbox = false

local Toolbar = plugin:CreateToolbar("Camera Physics (Run Mode Only)")

local Active = Toolbar:CreateButton(
	"Active",
	"Enables/Disables the camera hitbox.",
	"rbxassetid://17152447927"
)

Active.Click:Connect(function()
	if IsActive == false then
		IsActive = true
	else
		IsActive = false
	end
end)

local SquareMode = Toolbar:CreateButton(
	"Square",
	"Makes the camera hitbox a square, which will not rotate. Great for pushing parts such as dominoes.",
	"rbxassetid://17152521948"
)

SquareMode.Click:Connect(function()
	if UseSquareHitbox == false then
		UseSquareHitbox = true
	else
		UseSquareHitbox = false
	end
end)

-----

local CameraSphere = Instance.new("Part")
game["Run Service"].Stepped:Connect(function()
	if UseSquareHitbox == false then
		CameraSphere.Shape = "Ball"
	else
		CameraSphere.Shape = "Block"
	end
	CameraSphere.Transparency = 1
	CameraSphere.CanCollide = true
	CameraSphere.CastShadow = false
	CameraSphere.Size = Vector3.new(5, 5, 5)
	CameraSphere.Anchored = true
	CameraSphere.Name = "Physics"
	if CameraSphere and CameraSphere.Parent ~= nil then
		if IsActive == true then
			if 	CameraSphere.Parent ~= workspace then
                pcall(function()
                    CameraSphere.Parent = workspace
                end)
			end
		else
			if 	CameraSphere.Parent ~= game.ServerStorage then
				CameraSphere.Parent = game.ServerStorage
			end
		end
	end
	CameraSphere:PivotTo(workspace.Camera.CFrame)
	if UseSquareHitbox == true then
		CameraSphere.Orientation = Vector3.new(0, 0, 0)
	end
	for i, obj in pairs(workspace:GetDescendants()) do
		if obj and obj:FindFirstChildOfClass("Humanoid") and obj:FindFirstChild("Head") and obj:FindFirstChild("HumanoidRootPart") and obj:FindFirstChild("Head"):FindFirstChild("face") then
			if CameraSphere and CameraSphere:IsA("Part") then
				CameraSphere:Destroy()
			end
		end
	end
end)

still errors the same thing, same line.
edit: nevermind. i had 2 versions running at the same time XD