How would I make the touched event only fire once?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Im trying to make a door that opens based on which side of the door your on, say for example your on the back side of it, it would open forwards, if you were on the forward side it would open backwards.
  2. What is the issue? Include screenshots / videos if possible!
    robloxapp-20230605-1424107.wmv (1.6 MB)
    It works the first time, but then after without player input just touching the hitbox makes it open
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried adding debounces/pauses but it just won’t work

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Players = game:GetService("Players")
local HitboxA = script.Parent.HitboxA
local HitboxB = script.Parent.HitboxB
local tcouhgeda = game.ReplicatedStorage.TouchedA
local tcouhgedb = game.ReplicatedStorage.Touchedb
local Proxy = script.Parent.Parent.OpenProximityPrompt.ProximityPrompt
local pause = false
local Door = script.Parent
Proxy.Triggered:Connect(function()
	if pause then
		return
	end
	pause = true
	print("workingproxy")
	HitboxA.Touched:Connect(function(touched)
		if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
			local Player = Players:GetPlayerFromCharacter(touched.Parent)
			if Player then
				print(Player)
				tcouhgeda:FireClient(Player, Door)
			end
		end
		end)
                end)
1 Like

Probably once the touched event triggers you can turn off cancollide or maybe even canquery.

@DasKairo has a better solution

Replace :Connect with :Once

2 Likes

Use :Once instead of :Connect

Characters

Your’s was actually better cause once wouldn’t even play the function at all, however turning off cantouch once it gets activated actually worked

1 Like

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