Help with Touch Event

I made a train game and I want the it so when the vehicle Seat of the first carraige (trainCarraige1) touches a part, after a while, the value in the part becomes true for 5 seconds before going back to false. It works fine, however, after 5 seconds, the value is sometimes still true. Could it be because when the train is leaving the platform, the vehicle seat continues to touch it?

local part = script.Parent
local waitingtime = script.Parent:FindFirstChild("WaitingTime")
local ring = script:FindFirstChild("Ringing")

ring.Value = false

part.Touched:Connect(function(HittedPart)
	if HittedPart.Name == "VehicleSeat" and HittedPart.Parent.Name == "TrainCarraige1" then
		ring.Value = false
		wait(5)
		wait(waitingtime.Value)
		ring.Value = true
		wait(5)
		ring.Value = false
		wait(20) 
	end
end)

There’s no debounce.


local part = script.Parent
local waitingtime = script.Parent:FindFirstChild("WaitingTime")
local ring = script:FindFirstChild("Ringing")

ring.Value = false
local debounce = false
part.Touched:Connect(function(HittedPart)
if not debounce then
debounce = true
	if HittedPart.Name == "VehicleSeat" and HittedPart.Parent.Name == "TrainCarraige1" then
		ring.Value = false
		wait(5)
                debounce = false
		wait(waitingtime.Value)
		ring.Value = true
		wait(5)
		ring.Value = false
		wait(20) 
	end
end)

wait what is the script for?? can u pls explain it clearer so i can help?

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