How to add debounce to mouseclick on npc

how to add it ?
script:


local rep = game:GetService("ReplicatedStorage")
local cam2 = game.Workspace.cam

local cam = workspace.CurrentCamera

local ree = rep:WaitForChild("ree")

local ts = game:GetService("TweenService")

local dummie = game.Workspace.Dummy


local players =  game:GetService("Players")
local plr = players.LocalPlayer

local plrgui = plr.PlayerGui

local screengui = plrgui.ScreenGui
screengui.Enabled = false
local frame = screengui:WaitForChild("Frame")

local textlabel = frame:WaitForChild("TextLabel")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local AnimateUI = require(ReplicatedStorage:WaitForChild("AnimateUI"))

local mouse = dummie:WaitForChild("ClickDetector")

local textbutton = frame:WaitForChild("TextButton")
local debounce = false
textbutton.MouseButton1Click:Connect(function()


	screengui.Enabled = false
	cam.CameraType = "Custom"


	textlabel.Text = ""

end)
mouse.MouseClick:Connect(function()
	debounce = true
	screengui.Enabled = true








	cam.CameraType = "Scriptable"
	local tweeninfo = TweenInfo.new(2)
	local tween =  ts:Create(cam,tweeninfo, {CFrame = cam2.CFrame})
	tween:Play()
	wait(2)

	if screengui.Enabled == true then






		local message1 = [[hello]]
		AnimateUI.typeWrite(textlabel, message1, 0.05)

		wait(1)

		local message2 = [[want free robux?]]
		AnimateUI.typeWrite(textlabel, message2, 0.05)

		wait(25)
		debounce = false
	end

end)

robloxapp-20220228-0941388.wmv (3.2 MB)

Does this work:

local rep = game:GetService("ReplicatedStorage")
local ts = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local players =  game:GetService("Players")
local plr = players.LocalPlayer
local plrgui = plr.PlayerGui
local screengui = plrgui.ScreenGui
local frame = screengui:WaitForChild("Frame")
local textlabel = frame:WaitForChild("TextLabel")
local textbutton = frame:WaitForChild("TextButton")

local cam = workspace.CurrentCamera
local cam2 = game.Workspace.cam

local ree = rep:WaitForChild("ree")
local dummie = game.Workspace.Dummy

local AnimateUI = require(ReplicatedStorage:WaitForChild("AnimateUI"))

local mouse = dummie:WaitForChild("ClickDetector")

local debounce = false

screengui.Enabled = false

textbutton.MouseButton1Click:Connect(function()

	screengui.Enabled = false
	cam.CameraType = "Custom"

	textlabel.Text = ""

end)
mouse.MouseClick:Connect(function()
	debounce = true
	screengui.Enabled = true

	cam.CameraType = "Scriptable"
	local tweeninfo = TweenInfo.new(2)
	local tween =  ts:Create(cam,tweeninfo, {CFrame = cam2.CFrame})
	tween:Play()
	wait(2)

	if screengui.Enabled == true then
		local message1 = [[hello]]
		AnimateUI.typeWrite(textlabel, message1, 0.05)

		wait(1)

		local message2 = [[want free robux?]]
		AnimateUI.typeWrite(textlabel, message2, 0.05)

	end
	wait(25)
	debounce = false

end)

nope still buggy :sad:

Does that work?

local rep = game:GetService("ReplicatedStorage")
local cam2 = game.Workspace.cam

local cam = workspace.CurrentCamera

local ree = rep:WaitForChild("ree")

local ts = game:GetService("TweenService")

local dummie = game.Workspace.Dummy


local players =  game:GetService("Players")
local plr = players.LocalPlayer

local plrgui = plr.PlayerGui

local screengui = plrgui.ScreenGui
screengui.Enabled = false
local frame = screengui:WaitForChild("Frame")

local textlabel = frame:WaitForChild("TextLabel")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local AnimateUI = require(ReplicatedStorage:WaitForChild("AnimateUI"))

local mouse = dummie:WaitForChild("ClickDetector")

local textbutton = frame:WaitForChild("TextButton")
local debounce = false
textbutton.MouseButton1Click:Connect(function()


	screengui.Enabled = false
	cam.CameraType = "Custom"


	textlabel.Text = ""

end)
mouse.MouseClick:Connect(function()
	screengui.Enabled = true








	cam.CameraType = "Scriptable"
	local tweeninfo = TweenInfo.new(2)
	local tween =  ts:Create(cam,tweeninfo, {CFrame = cam2.CFrame})
	tween:Play()
	wait(2)

	if screengui.Enabled == true and debounce == false then
debounce = true





		local message1 = [[hello]]
		AnimateUI.typeWrite(textlabel, message1, 0.05)

		wait(1)

		local message2 = [[want free robux?]]
		AnimateUI.typeWrite(textlabel, message2, 0.05)

		wait(25)
		debounce = false
	end

end)
1 Like