How to detect if you stop colliding with a part properly

im currently making a fridge that when u are inside with the door closed a freezing gui fades in and fades out when u get out
issue is that the collide event only apparently works when the player moves and when it stands still it stops
ive tried searching for it but i found nothing somehow
this is what happens

this is the client side code for it

wait(1)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local guiObjects = {}
local partToCollideWith = workspace.Fridge.ez
local fadeSpeedIn = 0.05
local fadeSpeedOut = 0.05
local maxTransparency = 0

for i = 1, 10 do
	table.insert(guiObjects, player.PlayerGui.frost:WaitForChild("overlay" .. i))
end

local function changeTransparency(value)
	for _, guiObject in pairs(guiObjects) do
		guiObject.ImageTransparency = value
	end
end

local function onTouch(hit)
	if hit.Parent == character then
		print("yes")
		for transparency = 1, maxTransparency, -fadeSpeedIn do
			if partToCollideWith.Parent.Partez.Value.Value == false then
				changeTransparency(transparency)
				wait(0.05)
				print("YES")
			end
		end
	end
end

local function onTouchEnded(hit)
	if hit.Parent == character then
		while guiObjects[1].ImageTransparency < 1 do
			for _, guiObject in pairs(guiObjects) do
				guiObject.ImageTransparency = guiObject.ImageTransparency + fadeSpeedOut
			end
			wait(0.05)
		end
	end
end

partToCollideWith.Touched:Connect(onTouch)
partToCollideWith.TouchEnded:Connect(onTouchEnded)

this is my first ever post so sry if im bad at it

1 Like

Maybe try to use a raycast instead of .touched and fire it from the players feet, then make it detect the part you want to detect

dam i never thought about that wow lol tysm even if i abandoned the project

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.