How to fix this problem (script like TouchedEnded) [Scripts + Video]

Hello, as you can see on the video, there is a problem with the function that allows to take into account that the player is no longer on the platform. Indeed, the platform blinks while the player is on it while it should stay in Neon without changing color until the player actually leaves the platform. Does anyone know how I can fix this? the script is below the video. Thank you

--Server Script
script.Parent.A.Touched:Connect(function(hit)
end)
local player_list = {}

while task.wait() do
	local tool_equipped = false
	local part = "A"
	for i,hit in pairs(script.Parent[part]:GetTouchingParts()) do
		player_1 = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player_1 then
				script.Parent[part].Material = Enum.Material.Neon --Part touched
				tool_equipped = true
				break
			end
	    end
	if not tool_equipped and script.Parent[part].Material == Enum.Material.Neon then
		script.Parent[part].Material = Enum.Material.Plastic --Part untouched
	end

I would use a table (or variable) that tells the script what players are already on the platform, and if the player is already on the platform, then you just let the script continue looping until the player gets off

I don’t think it should be inside of a loop, you can do it without looping it.

Yes it should be, if it not in the loop then the script doesn’t work

I’m going to find out about it

Try printing out the conditions to identify the problem.


I need a debounce

if player_1 then
				script.Parent[part].Material = Enum.Material.Neon
			tool_equipped = true
			print("hii1")
				break

Honestly I can’t apply the first solution for the variables with my script and the debounce doesn’t really fix the problem. Does anyone have an idea?

I found a solution, remove cancollide to the the part

Solution. Just make sur that CanCollide is off in the parts and there will be no problem. Ideally add a debounce into the script for prevent lag.

Say, why does it have to be in a loop, is it to see if the player has a tool equipped? You can just accomplish it with just the touch event since player will still need to touch the brick. Anyways, the problem seem to be tool_equipped. Try printing hit.Parent, make sure it’s a character.