Cant get OverlapParams working

In this game, im trying to create a system where players are protected from outside elements (ie, if you’re cold, when you go inside you get warm)

local Part = game.Workspace.HouseHitbox --- Hitbox thats going over house
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character

if not character or not character.Parent then
	character = player.CharacterAdded:wait() -- this is done in a localscript, need this, unless this should be done in a server script.
end

local Params = OverlapParams.new() 
Params.FilterType = Enum.RaycastFilterType.Whitelist
Params.FilterDescendantsInstances = {player.Character}
print(character) -- Checking to see if character is added, it is
print(Params)
local TouchingParts = workspace:GetPartsInPart(Part, Params) 
if #TouchingParts > 0 then
	--player is inside this hitbox, safe
	print('player is safe')
end

This all makes sense, however it does nothing. So im not sure where im messing up at.

With this setup, how come when im touching the part, nothing is happening?

The issue is when you are checking

This means you check the area once in this line. If you want to check continuously you will need to loop it forever, a simple while true do task.wait(1) should suffice. For better alternatives see zone+.

1 Like

using while true do with a wait just made studio crash, instead I went with using RunService.Heartbeat

All is working now!

I have another question though, i’m trying to put all these hitbox parts in a folder and then run code (as you can see in the original post, Part is only one specific part, but its going to be a folder of parts)

For this, I created a folder called ProtectionPoints.

New code looks like this

local RunService = game:GetService("RunService")


local Part = game.workspace:WaitForChild("ProtectionPoints"):GetChildren()
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character

if not character or not character.Parent then
	character = player.CharacterAdded:wait()
end

local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Whitelist
Params.FilterDescendantsInstances = {player.Character}
print(character)
print(Params)


RunService.Heartbeat:Connect(function()
	local TouchingParts = workspace:GetPartsInPart(Part, Params)
	if #TouchingParts > 0 then
		print('player is in safe')
		--return
	end
end)

Part is now suppose to be all the items in the folder. However i get this error in my code Unable to cast value to Object on this line:
local TouchingParts = workspace:GetPartsInPart(Part, Params)

I assume its doing that because Part is now = to the children of the folder.

How exactly should I go about this? I’m trying to make all the parts in the folder at like this part. The code works with one part, just not multiple.