local q=10 local U=25 local Q=game.Players.LocalPlayer local T=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")game.ReplicatedStorage.Interactions.Client.Perks.UseXRay.OnClientEvent:connect(function()if Q.Character~=nil then local R=Q.Character Q.PlayerGui.MainGui.Tip.Text="\080\114\101\115\115 \081 \116\111 \117\115\101 \088-\082\097\121"local D=workspace:FindFirstChild("\077\097\112")local L=false local Z local e=false Z=T.InputBegan:connect(function(T)if not L and(not e and(T.KeyCode==Enum.KeyCode.Q and workspace:FindFirstChild("\077\097\112")==D))then L=true local T=game.ReplicatedStorage.Interactions.Server.GetPlayingPlayers:InvokeServer()for q,U in pairs(T)do if U==Q then table.remove(T,q)break end end for U,Q in pairs(T)do local T=Q.Character if T~=nil and(T:FindFirstChild("\072\117\109\097\110\111\105\100")and(T.Humanoid.Health>0 and T:FindFirstChild("\084\111\114\115\111")))then local U=script.XMarker:clone()U.Parent=T.Torso spawn(function()wait(q)if U~=nil then U:destroy()U=nil end end)T.Humanoid.Died:connect(function()if U~=nil then U:destroy()U=nil end end)end end for U=1,q,1 do if e or workspace:FindFirstChild("\077\097\112")==nil then break end Q.PlayerGui.MainGui.Tip.Text="\067\097\110 \115\101\101 \111\116\104\101\114\115 \102\111\114 "..((q-U)+1 .." \115\101\099\111\110\100\115")wait(1)end if not e and workspace:FindFirstChild("\077\097\112")then for q=1,U,1 do if e or workspace:FindFirstChild("\077\097\112")==nil then break end Q.PlayerGui.MainGui.Tip.Text="\067\097\110 \117\115\101 \097\103\097\105\110 \105\110 "..((U-q)+1 .." \115\101\099\111\110\100\115")wait(1)end if not e and workspace:FindFirstChild("\077\097\112")then Q.PlayerGui.MainGui.Tip.Text="\080\114\101\115\115 \081 \116\111 \116\117\114\110 \117\115\101 \088-\082\097\121"end end if e or workspace:FindFirstChild("\077\097\112")==nil then if Z~=nil then Z:disconnect()Z=nil end e=true Q.PlayerGui.MainGui.Tip.Text=""end L=false elseif workspace:FindFirstChild("\077\097\112")~=D then if Z~=nil then Z:disconnect()Z=nil end e=true Q.PlayerGui.MainGui.Tip.Text=""end end)R.Humanoid.Died:connect(function()if not e then Z:disconnect()Z=nil e=true Q.PlayerGui.MainGui.Tip.Text=""end end)end end)
-- General settings
local XRAY_TIME = 10
local COOLDOWN = 25

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

game.ReplicatedStorage.Interactions.Client.Perks.UseXRay.OnClientEvent:connect(function()
	-- Make sure character is alive
	if plr.Character ~= nil then
		local originalChr = plr.Character

		-- Show tip
		plr.PlayerGui.MainGui.Tip.Text = "Press Q to use X-Ray"

		-- Set map object
		local map = workspace:FindFirstChild("Map")

		-- Connect input event
		local debounce = false
		local event
		local done = false
		event = inputService.InputBegan:connect(function(inputObj)
			-- Check if states are correct
			if
				not debounce
				and not done
				and inputObj.KeyCode == Enum.KeyCode.Q
				and workspace:FindFirstChild("Map") == map
			then
				debounce = true

				-- Show location of each player
				local playingPlayers = game.ReplicatedStorage.Interactions.Server.GetPlayingPlayers:InvokeServer()
				for n, i in pairs(playingPlayers) do
					if i == plr then
						table.remove(playingPlayers, n)
						break
					end
				end
				for _, i in pairs(playingPlayers) do
					-- Make sure character is alive
					local chr = i.Character
					if
						chr ~= nil
						and chr:FindFirstChild("Humanoid")
						and chr.Humanoid.Health > 0
						and chr:FindFirstChild("Torso")
					then
						-- Place X Gui in torso
						local gui = script.XMarker:clone()
						gui.Parent = chr.Torso

						-- Remove after 10 seconds
						spawn(function()
							wait(XRAY_TIME)
							if gui ~= nil then
								gui:destroy()
								gui = nil
							end
						end)

						-- Connect death
						chr.Humanoid.Died:connect(function()
							if gui ~= nil then
								gui:destroy()
								gui = nil
							end
						end)
					end
				end

				-- Update text to match state
				for i = 1, XRAY_TIME do
					if done or workspace:FindFirstChild("Map") == nil then
						break
					end
					plr.PlayerGui.MainGui.Tip.Text = "Can see others for " .. (XRAY_TIME - i + 1) .. " seconds"
					wait(1)
				end
				if not done and workspace:FindFirstChild("Map") then
					for i = 1, COOLDOWN do
						if done or workspace:FindFirstChild("Map") == nil then
							break
						end
						plr.PlayerGui.MainGui.Tip.Text = "Can use again in " .. (COOLDOWN - i + 1) .. " seconds"
						wait(1)
					end
					if not done and workspace:FindFirstChild("Map") then
						plr.PlayerGui.MainGui.Tip.Text = "Press Q to turn use X-Ray"
					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 disconnect
		originalChr.Humanoid.Died:connect(function()
			if not done then
				event:disconnect()
				event = nil
				done = true
				plr.PlayerGui.MainGui.Tip.Text = ""
			end
		end)
	end
end)
