OK So I have a script that when an AI/NPC touches it then it fires an event. The problem is that It stands there and waits for the user to give it a command. But when it stands there it is still running the touched event and the Touched event then starts to cause lag and slow the entire game down.
Here is the code if that helps.
Part = script.Parent
Waiting = script.Parent.Waiting
Seat = script.Parent.Seat
SeatNumber = script.Parent.SeatNumber
WaitingInLine = script.Parent.WaitingInLine
local DidHit = false
Part.Touched:connect(function(HIT)
local TimerStart = HIT.Parent.Moods.TimerStart
if not DidHit then
DidHit = true
if HIT.Parent.Monster.Value == true then
print("Monster")
--Start Mood Timer
TimerStart.Value = true
WaitingInLine.Value = true
while Waiting.Value == true do
print("ITs In The While Loop")
if Seat.Value == true then
HIT.Parent.Destination.Value = SeatNumber.Value
Waiting.Value = false
else
wait(0.5)
end
wait(0.1)
end
wait(3)
DidHit = false
else
print("Human")
end
end
end)
The thing is I only want the event to work when the NPC walks into the Object but its constantly firing even when the NPC stands still. Is there any way to make it not do that. ALSO I TRIED DEBOUNCE AND THAT DOESNT WORK BECAUSE THE EVENT STILL FIRES REGARDLESS.
