local ui_creation = {}
local abilityUI = game.Players.LocalPlayer.PlayerGui:WaitForChild("abilityUI")
local UserInputService = game:GetService("UserInputService")
local rai = "rbxassetid://"

ui_creation.canUse_ability1 = true
ui_creation.canUse_ability2 = true
ui_creation.canUse_ability3 = true
ui_creation.canUse_ability4 = true

ui_creation.cooldown1 = 0

ui_creation.cooldown2 = 0

ui_creation.cooldown3 = 0
ui_creation.cooldown4 = 0



ui_creation.Abilities = {
	Ability1 = nil,
	Ability2  = nil,
	Ability3 = nil,
	Ability4 = nil,
}


ui_creation.KillerKeybinds = {
	["One"] = "MouseButton1";
	["Two"] = "Q";
	["Three"] = "E";
	["Four"] = "R"
}
ui_creation.Keybinds = {

	["One"] = "Q";
	["Two"] = "E";
	["Three"] = "R"
}
local plr = game.Players.LocalPlayer

print("stuff before function - works")

ui_creation.CreateAbilityUI = function(
	Name,
	Ab1Image,
	Ab2Image,
	Ab3Image,
	Ab4Image,
	Ab1Name,
	Ab2Name, 
	Ab3Name, 
	Ab4Name,
	Ab1Cooldown,
	Ab2Cooldown,
	Ab3Cooldown,
	Ab4Cooldown
)



	local newUI = abilityUI:Clone()
	newUI.Name = Name
	if plr.Char.Value == newUI.Name  then
		
	local buttons = {newUI:WaitForChild("Ability1"), newUI:WaitForChild("Ability2"), newUI:WaitForChild("Ability3"), newUI:WaitForChild("Ability4")}
	local cooldowns = {buttons[1].TextLabel, buttons[2].TextLabel, buttons[3].TextLabel, buttons[4].TextLabel}
	newUI.Parent = plr.PlayerGui
	
	newUI.Enabled = true
	print("stuff before naming, works")

	local function startCooldown(index, duration)
		local cooldowns = {
			[1] = function()
				ui_creation.canUse_ability1 = false
				local btn = abilityUI:FindFirstChild("Ability1")
				local label = btn and btn:FindFirstChild("TextLabel")
				for i = duration, 1, -1 do
					if label then
						label.Visible = true
						label.Text = tostring(i)
					end
					ui_creation.cooldown1 = i
					task.wait(1)
				end
				if label then
					label.Visible = false
				end
				ui_creation.canUse_ability1 = true
				ui_creation.cooldown1 = 0
			end,
			[2] = function()
				ui_creation.canUse_ability2 = false
				local btn = abilityUI:FindFirstChild("Ability2")
				local label = btn and btn:FindFirstChild("TextLabel")
				for i = duration, 1, -1 do
					if label then
						label.Visible = true
						label.Text = tostring(i)
					end
					ui_creation.cooldown2 = i
					task.wait(1)
				end
				if label then
					label.Visible = false
				end
				ui_creation.canUse_ability2 = true
				ui_creation.cooldown2 = 0
			end,
			[3] = function()
				ui_creation.canUse_ability3 = false
				local btn = abilityUI:FindFirstChild("Ability3")
				local label = btn and btn:FindFirstChild("TextLabel")
				for i = duration, 1, -1 do
					if label then
						label.Visible = true
						label.Text = tostring(i)
					end
					ui_creation.cooldown3 = i
					task.wait(1)
				end
				if label then
					label.Visible = false
				end
				ui_creation.canUse_ability3 = true
				ui_creation.cooldown3 = 0
			end,
			[4] = function()
				ui_creation.canUse_ability4 = false
				local btn = abilityUI:FindFirstChild("Ability4")
				local label = btn and btn:FindFirstChild("TextLabel")
				for i = duration, 1, -1 do
					if label then
						label.Visible = true
						label.Text = tostring(i)
					end
					ui_creation.cooldown4 = i
					task.wait(1)
				end
				if label then
					label.Visible = false
				end
				ui_creation.canUse_ability4 = true
				ui_creation.cooldown4 = 0
			end
		}

		if cooldowns[index] then
			task.spawn(cooldowns[index])
		end
	end



	buttons[1].AbilityName.Text = Ab1Name
	buttons[1].Image = rai..tostring(Ab1Image)

	buttons[2].AbilityName.Text = Ab2Name
	buttons[2].Image =rai..tostring(Ab2Image)


	buttons[3].AbilityName.Text = Ab3Name
	buttons[3].Image = rai..tostring(Ab3Image)

	buttons[4].AbilityName.Text = Ab4Name
	buttons[4].Image = rai..tostring(Ab4Image)
	print("working")

	task.spawn(function()
		while true do
			if ui_creation.cooldown1 > 0 then
				ui_creation.canUse_ability1 = false
				cooldowns[1].Visible = true
				cooldowns[1].Text = tostring(ui_creation.cooldown1)
			else
				ui_creation.canUse_ability1 = true
				cooldowns[1].Visible = false
			end

			if ui_creation.cooldown2 > 0 then
				ui_creation.canUse_ability2 = false
				cooldowns[2].Visible = true
				cooldowns[2].Text = tostring(ui_creation.cooldown2)
			else
				ui_creation.canUse_ability2 = true
				cooldowns[2].Visible = false
			end

			if ui_creation.cooldown3 > 0 then
				ui_creation.canUse_ability3 = false
				cooldowns[3].Visible = true
				cooldowns[3].Text = tostring(ui_creation.cooldown3)

			else
				ui_creation.canUse_ability3 = true
				cooldowns[3].Visible = false
			end

			if ui_creation.cooldown4 > 0 then
				ui_creation.canUse_ability4 = false
				cooldowns[4].Visible = true
				cooldowns[4].Text = tostring(ui_creation.cooldown4)

			else
				ui_creation.canUse_ability4 = true
				cooldowns[4].Visible = false
			end
			task.wait(0)

		end

	end)

	print("stuff after loops - works")

	UserInputService.InputBegan:Connect(function(input, gameProcessed)
		if gameProcessed or UserInputService:GetFocusedTextBox() then return end
		local IsKiller = plr:WaitForChild("IsKiller")
		if IsKiller.Value == true then
			if input.UserInputType == Enum.UserInputType.MouseButton1 then
				if ui_creation.canUse_ability1 then
					ui_creation.Abilities.Ability1()
					print("used ability")
					ui_creation.canUse_ability1 = false
					startCooldown(1, Ab1Cooldown)
				end
			elseif input.KeyCode == Enum.KeyCode.Q then
				if ui_creation.canUse_ability2 then
					ui_creation.canUse_ability2 = false

					print("used ability")
						ui_creation.Abilities.Ability2()

					startCooldown(2, Ab2Cooldown)
				end
			elseif  input.KeyCode == Enum.KeyCode.E then
				if ui_creation.canUse_ability3 then

					print("used ability")
					ui_creation.canUse_ability3 = false
						ui_creation.Abilities.Ability3()
					startCooldown(3, Ab3Cooldown)
					
				end
			elseif  input.KeyCode == Enum.KeyCode.R then
				if ui_creation.canUse_ability4 then

					ui_creation.canUse_ability4 = false

					ui_creation.Abilities.Ability4()
					
					print("used ability")
						startCooldown(4, Ab4Cooldown)

				end
			end
		end
		if IsKiller.Value == false then
			if  input.KeyCode == Enum.KeyCode.Q then
				if ui_creation.canUse_ability1 then
					ui_creation.Abilities.Ability1()
					ui_creation.canUse_ability1= false
					print("used ability")
					startCooldown(1, Ab1Cooldown)

				end
			elseif  input.KeyCode == Enum.KeyCode.E then
				if ui_creation.canUse_ability2 then
					ui_creation.Abilities.Ability2()
					ui_creation.canUse_ability2 = false
					print("used ability")
					ui_creation.cooldown2 = Ab2Cooldown
					startCooldown(2, Ab2Cooldown)

				end
			elseif  input.KeyCode == Enum.KeyCode.R then
				if ui_creation.canUse_ability3 then
					ui_creation.Abilities.Ability3()
					ui_creation.canUse_ability3 = false
					print("used ability")
					startCooldown(3, Ab3Cooldown)
				end

			end
		end


	end)end
	print("stuff done")
end
print("EVERYTHING works")
return ui_creation why dont the abilities work everything else works but the ability fire dont