How could i check if a item is placed

I am trying to make a rat that when you place the cheese on the plate in front of him it will come, pick up the cheese, go back, and give you a item. I succeded to make the rat come pick the cheese and give the item but only when every condition is right. I know how should i fix it but it didn t really work. I should check if the cheese is on the plate at the statement “if true then” that i put just so i don t get any errors. I would like if you could tell me how to check if the cheese is on the plate, that s all I need.

As for what i tried for now, i tried to check if the plate is touching the cheese and some not so efficient ideas that are not worth to mention.

Note: I also have a local script to place the cheese that i put after this one:

local player = game.Players.LocalPlayer
local plate = workspace.Plate
local rat = game.Workspace.Louie
local originalPosition = rat.Position
local weld1 = rat.WeldConstraint
local weld2 = rat.weld2
local bell = workspace.Bell
local gotopart = workspace.Gotopart
local cheesePart = workspace.Cheese.Union
local var = plate.Value

var:GetPropertyChangedSignal("Value"):Connect(function()
	print("asda")
end)


bell.Model.ClickDetector.MouseClick:Connect(function()
	goToCheese()
end)

function goToCheese()
	local cheeseDirection = (gotopart.Position - rat.Position).unit
	local distanceToCheese = (gotopart.Position - rat.Position).magnitude

	print("Going to the cheese")

	if true then --this is where i need to check if the cheese is on the plate
		for i = 1, math.floor(distanceToCheese) do
			rat.CFrame = CFrame.new(rat.Position + cheeseDirection)
			wait(0.1)
		end
		print("ashds")
		wait(1)
		weld1.Part1 = cheesePart.Parent.Handle

		wait(3) 
		
		for i = 1, math.floor(distanceToCheese) do
			rat.CFrame = CFrame.new(rat.Position - cheeseDirection)
			wait(0.1)
		end

		weld1.Part1 = nil
		cheesePart.Parent:Destroy()
		weld2.Part1 = workspace.TestTool.Part

		wait(3) 

		
		for i = 1, math.floor(distanceToCheese) do
			rat.CFrame = CFrame.new(rat.Position + cheeseDirection)
			wait(0.1)
		end

		weld2.Part1 = nil

		wait(3)

		for i = 1, math.floor(distanceToCheese) do
			rat.CFrame = CFrame.new(rat.Position - cheeseDirection)
			wait(0.1)
		end

	else
		for i = 1, math.floor(distanceToCheese) do
			rat.CFrame = CFrame.new(rat.Position + cheeseDirection)
			wait(0.1)
		end
		
		wait(1) 
		
		for i = 1, math.floor(distanceToCheese) do
			rat.CFrame = CFrame.new(rat.Position - cheeseDirection)
			wait(0.1)
		end
	end
end

local player = game.Players.LocalPlayer
local plate = workspace.Plate
local cheese = workspace.Cheese
local var = plate.Value
local char = player.Character

plate.ClickDetector.MouseClick:Connect(function()
	local tool = player.Backpack:FindFirstChild("Cheese") 
	if tool then
		var.Value = true
		tool.Parent = plate
		tool.Handle.CFrame = plate.CFrame -- Snap the tool's position to the plate
		tool:SetPrimaryPartCFrame(plate.CFrame) 
		tool:SetPrimaryPartCFrame(tool.PrimaryPart.CFrame + Vector3.new(0, tool.PrimaryPart.Size.Y / 2, 0)) 
		tool.PrimaryPart.Anchored = false
		print("Tool placed on the plate.")
	end
end)

Here is a picture with the situation if it helps:

2 Likes

You could try using hitboxes such as region3 or you could use zone plus

1 Like

I ll keep in mind to try that, thanks for helping!

1 Like