Help: Sometimes, the code bugs weirdly

Hello developers!

So I was testing my code on a hiding spot with my friend, but the code seems to bug sometimes, and what’s more weirder is that the output doesn’t say anything, I needed to reach out to developers, and that’s why this topic is here.

LocalScript


local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local UnhideButton = Player.PlayerGui:WaitForChild("Unhide"):WaitForChild("Mobile")

local debounce = false

UserInputService.InputBegan:Connect(function(input, isTyping)
	if isTyping then return end
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if (input.KeyCode == Enum.KeyCode.W
			or input.KeyCode == Enum.KeyCode.A
			or input.KeyCode == Enum.KeyCode.S
			or input.KeyCode == Enum.KeyCode.D)
		then
			if not debounce then
				debounce = true
				game.ReplicatedStorage.GoOutLocker:FireServer()
				task.wait(0.5)
				debounce = false
			end
		end
	end
end)

if UserInputService.TouchEnabled then
	UnhideButton.Visible = true
	UnhideButton.MouseButton1Click:Connect(function()
		debounce = true
		game.ReplicatedStorage.GoOutLocker:FireServer()
		task.wait(0.5)
		debounce = false
	end)
end

Script


local Tween_Service = game:GetService("TweenService")
local dooropen = script.Parent.Parent.dooropen
local ProximityPrompt = script.Parent.ProximityPrompt
local PlayerHidden = script.Parent.Parent.PlayerHidden
local Hiding = script.Parent.Parent.Hiding
local Old_Position = script.Parent.CFrame

local debounce = false

ProximityPrompt.Triggered:Connect(function(plr)
	if Hiding.Value == false and debounce == false then
		debounce = true
		local HumanoidRootPart = plr.Character:WaitForChild("HumanoidRootPart")
		local Humanoid = plr.Character:FindFirstChildOfClass("Humanoid")
		if Humanoid.Health < 1 then return end
		if plr.Character:FindFirstChild("CantHide") then return end
		ProximityPrompt.MaxActivationDistance = 0
		PlayerHidden.Value = plr
		Hiding.Value = true
		local Canthide = Instance.new("BoolValue")
		local Hidden = Instance.new("BoolValue")
		Canthide.Name = "CantHide"
		Hidden.Name = "Hidden"
		Hidden.Parent = plr.Character
		Canthide.Parent = plr.Character
		script.Parent.Open:Play()
		local Anim = Tween_Service:Create(script.Parent, TweenInfo.new(0.5), {CFrame = dooropen.CFrame})
		Anim:Play()
		Anim.Completed:Wait()
		HumanoidRootPart.Anchored = true
		plr.Character:PivotTo(script.Parent.Parent.Inside.CFrame)
		task.wait(0.25)
		local Anim = Tween_Service:Create(script.Parent, TweenInfo.new(0.5), {CFrame = Old_Position})
		Anim:Play()
		Anim.Completed:Wait()
		script.Parent.Close:Play()
		task.wait(0.5)
		debounce = false
	end
end)

game.ReplicatedStorage.GoOutLocker.OnServerEvent:Connect(function(plr)
	if Hiding.Value == true and debounce == false then
		debounce = true
		local HumanoidRootPart = plr.Character:WaitForChild("HumanoidRootPart")
		local Humanoid = plr.Character:FindFirstChildOfClass("Humanoid")
		if Humanoid.Health < 1 then return end
		if plr ~= PlayerHidden.Value then return end
		ProximityPrompt.MaxActivationDistance = 0
		PlayerHidden.Value = plr
		Hiding.Value = false
		script.Parent.Open:Play()
		local Anim = Tween_Service:Create(script.Parent, TweenInfo.new(0.5), {CFrame = dooropen.CFrame})
		Anim:Play()
		Anim.Completed:Wait()
		HumanoidRootPart.Anchored = false
		PlayerHidden.Value = nil
		plr.Character:FindFirstChild("CantHide"):Destroy()
		plr.Character:FindFirstChild("Hidden"):Destroy()
		plr.Character:PivotTo(script.Parent.Parent.Inside.CFrame * CFrame.new(-5,0,0))
		task.wait(0.25)
		local Anim = Tween_Service:Create(script.Parent, TweenInfo.new(0.5), {CFrame = Old_Position})
		Anim:Play()
		Anim.Completed:Wait()
		script.Parent.Close:Play()
		task.wait(0.5)
		ProximityPrompt.MaxActivationDistance = 10
		debounce = false
	end
end)

you have a random )
image