Proximity Prompt triggers more than once

LockerDoor.ProximityPrompt.Triggered:Connect(function(plr)
	print('IT TRIGGER OH MY GOD PLEASE HELP ME')
		if Taken == false then
			if not plr:FindFirstChild('Safe') then
				Taken = true
				print('ok')

				PersonHiding = plr
				PersonCharacter = plr.Character

				local SafeValue = Instance.new('BoolValue', PersonCharacter)
				SafeValue.Name = "Safe"
				SafeValue.Value = true


				PersonCharacter.PrimaryPart.Anchored = true
				LockerDoor.Breath:Play()
				LockerDoor.Open:Play()

				local GetInAnimation = TweenService:Create(
					PersonCharacter.PrimaryPart,
					TweenInfo.new(
						0.3,
						Enum.EasingStyle.Sine,
						Enum.EasingDirection.Out,
						0
					),
					{
						CFrame = Position_In.CFrame
					}
				)

				GetInAnimation:Play()
			end
		end
		if Taken == true then
			print('exite')
			if plr == PersonHiding then
				print('exit')

				PersonCharacter.PrimaryPart.Anchored = false
				PersonCharacter:FindFirstChild('Safe'):Destroy()
				local GetInAnimation = TweenService:Create(
					PersonCharacter.PrimaryPart,
					TweenInfo.new(
						0.3,
						Enum.EasingStyle.Sine,
						Enum.EasingDirection.Out,
						0
					),
					{
						CFrame = Position_Out.CFrame
					}
				)

				GetInAnimation:Play()

				wait(0.1)
				FREE_LOCKER()

			end
		end
end)

This code is working fine, but when I trigger the proximity prompt, it automatically makes the player go out of the locker. How do I fix this? The functions are firing both at once. It’s very annoying.

2 Likes

You see the reason why is you do this

if taken == false then

and then you do

if taken == true then

This means when you run to check if it is equal to false, After that it runs to check if it is equal to true.
This means if you change it in one of the checks its going to still run the == true part cause it is not the same thing. I really dont know how to explain it any other way.

To fix this you can do this

if Taken == false then
-- your code
elseif Taken == true then
-- your code
end

This makes it so it wont run twice
1 Like

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