After I press the ProximityPrompt, the player character should go to a special place and an event is triggered when I arrive there.
However, I noticed that every time I press the ProximityPrompt and arrive there, the event is triggered twice, three times and so on. After looking into why this is, I found out that it is because of the humanoid.MoveToFinished.
I looked for a possible solution, but I couldn’t find anything that could possibly help me.
--
local debounce = false
ProximityPrompt.Triggered:Connect(function(player)
print("1")
if debounce == false then
debounce = true
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local torso = character:FindFirstChild("LowerTorso")
local leftHand = character:FindFirstChild("LeftHand")
if character and humanoid and torso and leftHand then
local path = PathFindingService:CreatePath()
path:ComputeAsync(torso.Position, targetPlate.Position)
humanoid:MoveTo(targetPlate.Position)
humanoid.MoveToFinished:Connect(function()
print("2")
local Weld = Instance.new("Weld", leftHand)
Weld.Part0 = leftHand
Weld.Part1 = takeInHandPart
PutPlateOnBack(humanoid, torso)
TakePlateGUIRE:FireClient(player)
end)
end
end
end)
TakePlateGUIRE.OnServerEvent:Connect(function()
debounce = false
end)