script.Parent.Touched

https://1drv.ms/i/s!AiFuGTCesQvdgo4-wm6tkAK83DTRFQ?e=twDa9f
I’ve been trying to make an iceberg lettuce for my pvz game for a long time now, and script.Parent.Touched(function() isn’t working. How do i fix this?

1 Like

Is mouth a model or like a part?

2 Likes

Mouth is a part. extrawordsoicansendthis

1 Like

You could try :GetPartBoundsInBox() instead. .Touched typically isn’t reliable for multiple touch events. Here’s a simple code example for your situation:

local FilterObj = {script.Parent} -- Objects you want to filter
local boxPosition = CFrame.new(0, 0, 0) -- Put in your part's postition
local boxSize = Vector3.new(0, 0, 0) -- Put in your part's size
local maxObjectsAllowed = 1 -- How many objects are allowed to touch it

local params = OverlapParams.new(FilterObj, Enum.RaycastFilterType.Exclude, maxObjectsAllowed, "Default")
local objectsInSpace = workspace:GetPartBoundsInBox(boxPosition, boxSize, params)

while wait() do -- Change the wait() to what fits your game the best (it shouldn't be too laggy)
	for i, v in pairs(objectsInSpace) do
		if v.Parent:FindFirstChild("Humanoid") then
			-- Do whatever
		end
	end
end
2 Likes

I put in what touching the part would do and changed all the parts to change. Yet, nothing happens.

1 Like

Sorry, try this updated script. Just put the script inside of the part.

local FilterObjects = {}
local MaxObjectsAllowed = 0

local Params = OverlapParams.new()
Params.CollisionGroup = "Default"
Params.FilterDescendantsInstances = FilterObjects
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.MaxParts = MaxObjectsAllowed

while wait() do
	local objectsInSpace = game.Workspace:GetPartsInPart(script.Parent, Params)
	
	for i, v in pairs(objectsInSpace) do
		if v.Parent:FindFirstChildOfClass("Humanoid") then
			-- do stuff here (but keep the break)
			break
		end
	end
end
1 Like

It… didn’t work. Very suprising.

1 Like

Did you get any errors or does the script just not do anything?

1 Like

I know I’m extremely late, but it just did nothing.

You have a task.wait(8) in your code, consider wrapping your touched logic in a

task.spawn(function())

or use task.delay() ----------------------------------------------------