This script works PERFECTLY fine, yet I feel there has to be a different / more professional way of this? Instead of settings a value to true and false and then waiting, yet if there is not this is perfectly fine for me.
local HorrorFOV = game:GetService("ReplicatedStorage").HorrorFOV
local RegularFOV = game:GetService("ReplicatedStorage").RegularFOV
local Detector = script.Parent
local horrorfovactive = true
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player and horrorfovactive then
print("Player touched part, firing "..HorrorFOV.Name.."!")
print(HorrorFOV.Name.." has been fired!")
horrorfovactive = false
horrorfovactive = true
Well, the only recommendation I can give you is to put horrorfovactive = false under the check on whether the player exists and if the horrorfovactive variable is true. Other than that, this is basically the most efficient way to do it. Debounces are a very common way for developers to add delay and there isn’t really a more efficient way (there are multiple other ways, just not efficient). I also recommend turning wait(3) to task.wait(3).
For me, I would have a return function when horrorFovActive == false. It makes it readable, at least for me. I would also have horrorFovActive = false set from the beginning to see where that debounce is located in case your script gets really big.