local N=25 local y=10 local o=game.Players.LocalPlayer local z=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")game.ReplicatedStorage.Interactions.Client.Perks.UseInvisibility.OnClientEvent:connect(function()if o.Character~=nil and o.Character:FindFirstChild("\072\117\109\097\110\111\105\100")then o.PlayerGui.MainGui.Tip.Text="\080\114\101\115\115 \081 \116\111 \116\117\114\110 \105\110\118\105\115\105\098\108\101"local A=workspace:FindFirstChild("\077\097\112")local Y=false local e local G=false e=z.InputBegan:connect(function(z)if z.KeyCode==Enum.KeyCode.Q and(not Y and(not G and workspace:FindFirstChild("\077\097\112")==A))then Y=true game.ReplicatedStorage.Interactions.Server.Perks.MakeInvisible:FireServer()for N=1,y,1 do if G or workspace:FindFirstChild("\077\097\112")==nil then break end o.PlayerGui.MainGui.Tip.Text="\073\110\118\105\115\105\098\108\101 \102\111\114 "..((y-N)+1 .." \115\101\099\111\110\100\115")wait(1)end if not G and workspace:FindFirstChild("\077\097\112")then for y=1,N,1 do if G or workspace:FindFirstChild("\077\097\112")==nil then break end o.PlayerGui.MainGui.Tip.Text="\067\097\110 \117\115\101 \097\103\097\105\110 \105\110 "..((N-y)+1 .." \115\101\099\111\110\100\115")wait(1)end if not G and workspace:FindFirstChild("\077\097\112")then o.PlayerGui.MainGui.Tip.Text="\080\114\101\115\115 \081 \116\111 \116\117\114\110 \105\110\118\105\115\105\098\108\101"end end if G or workspace:FindFirstChild("\077\097\112")==nil then if e~=nil then e:disconnect()e=nil end G=true o.PlayerGui.MainGui.Tip.Text=""end Y=false elseif workspace:FindFirstChild("\077\097\112")~=A then if e~=nil then e:disconnect()e=nil end G=true o.PlayerGui.MainGui.Tip.Text=""end end)o.Character.Humanoid.Died:connect(function()if not G then e:disconnect()e=nil G=true o.PlayerGui.MainGui.Tip.Text=""end end)end end)

local COOLDOWN_TIME = 25
local RUNTIME = 10

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

game.ReplicatedStorage.Interactions.Client.Perks.UseInvisibility.OnClientEvent:connect(function()
	
	-- Make sure character is alive
	if plr.Character ~= nil and plr.Character:FindFirstChild("Humanoid") then
		
		-- Show tip
		plr.PlayerGui.MainGui.Tip.Text = "Press Q to turn invisible"
		
		-- Set map object
		local map = workspace:FindFirstChild("Map")
	
		-- Listen for keypress
		local debounce = false
		local event
		local done = false
		event = inputService.InputBegan:connect(function(inputObj)
			
			-- Check if states are correct
			if inputObj.KeyCode == Enum.KeyCode.Q and not debounce and not done and workspace:FindFirstChild("Map") == map then
				debounce = true
				
				-- Tell server to make invisible
				game.ReplicatedStorage.Interactions.Server.Perks.MakeInvisible:FireServer()
				
				-- Update text to match state
				for i=1, RUNTIME do
					if done or workspace:FindFirstChild("Map") == nil then
						break
					end
					plr.PlayerGui.MainGui.Tip.Text = "Invisible for " .. (RUNTIME - i + 1) .. " seconds"
					wait(1)
				end
				if not done and workspace:FindFirstChild("Map") then
					for i=1, COOLDOWN_TIME do
						if done or workspace:FindFirstChild("Map") == nil then
							break
						end
						plr.PlayerGui.MainGui.Tip.Text = "Can use again in " .. (COOLDOWN_TIME - i + 1) .. " seconds"
						wait(1)
					end
					if not done and workspace:FindFirstChild("Map") then
						plr.PlayerGui.MainGui.Tip.Text = "Press Q to turn invisible"
					end
				end
				if done or workspace:FindFirstChild("Map") == nil then
					if event ~= nil then
						event:disconnect()
						event = nil
					end
					done = true
					plr.PlayerGui.MainGui.Tip.Text = ""
				end
				
				debounce = false
			elseif workspace:FindFirstChild("Map") ~= map then
				if event ~= nil then
					event:disconnect()
					event = nil
				end
				done = true
				plr.PlayerGui.MainGui.Tip.Text = ""
			end
			
		end)
		
		-- Connect character death
		plr.Character.Humanoid.Died:connect(function()
			if not done then
				event:disconnect()
				event = nil
				done = true
				plr.PlayerGui.MainGui.Tip.Text = ""
			end
		end)
		
	end
	
end)
