How to except a part from change in a script

I made a script that would automatically set the max activation distances and hold durations of click detectors and proximity prompts. However, there are a few situations where the click detectors’ and proximity prompts’ max activation distances would be too close, and thus requiring them to be “excepted” by the script. I tried doing this by adding the excepted prompts to a list, but it doesn’t work and doesn’t set the activation distances and hold durations at all.

Here is the code:

for _,v in pairs(game.Workspace:GetDescendants()) do
	local obj = workspace.Objectives
	local exceptions = {obj.Obj3Kitchen.ProximityPrompt}
	for _,v in ipairs(exceptions) do
		if v~= exceptions then
			if v:IsA("ClickDetector") then
				v.MaxActivationDistance=5
			elseif v:IsA("ProximityPrompt") then
				v.MaxActivationDistance=5
				v.HoldDuration=0.5
			end
		end
	end
end
1 Like

if v~= exceptions then

checks if v IS the table, exceptions.

So instead, use

if not table.find(exceptions,v) then

That searches if v is in the table.

hope i was able to help

1 Like

I also had to remove the “for _,v in ipairs(exceptions) do” part for it to work.

I overlooked that, that basically meant the code only executes for each exception, and since you check if v is an exception that doesn’t do anything at all.

2 Likes