How to make abilities not usable while using other abilities

I made an ability system. I’m trying to fix this trick where you could just use all the abilities on top of each other, how can I prevent this?

I tried adding a BoolValue and changing it when the RemoteEvent activates however the local script that triggers the event can’t detect the change as the BoolValue was changed on the server. Plus, the BoolValue should only enable back after the ability is done.

Local Script

local Button = script.Parent
local Frame = Button.Parent
local GUI = Frame.Parent
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local Player = Players.LocalPlayer
local Remote = Button:WaitForChild("RemoteEvent")
local Cooldown = 1
local Ready = false
local ButtonReady = false
local Occupied = Frame:WaitForChild("Occupied").Value




--[[Button.Activated:Connect(function()
	if Ready == true then
		print("Pressed!")
		Ready = false
		Remote:FireServer()
		for i = Cooldown,0,-0.1 do
			Button.Text = math.floor(i*10) / 10
			task.wait(0.1)
		end
		Button.Text = "Q"
		Ready = true
	end
end)]]

local function GoOnCooldown(CD:number)
	for i = CD,0,-0.1 do
		Button.Text = math.floor(i*10) / 10
		task.wait(0.1)
	end
end


GoOnCooldown(Cooldown/2)
Button.Text = "Q"
Ready = true

Button.Activated:Connect(function()
	if Ready == true and ButtonReady == false and Occupied == false then
		ButtonReady = true
		Button.BackgroundColor3 = Color3.fromRGB(85, 255, 0)
	else
		ButtonReady = false
		Button.BackgroundColor3 = Color3.fromRGB(255,255,255)
	end
end)

UIS.InputBegan:Connect(function(input,gameProcessed)
	local CurrentQ = UserSettings().GameSettings.SavedQualityLevel.Value
	if Ready == true and gameProcessed == false and GUI.Enabled == true and Occupied == false then
		print(Occupied)
		if input.KeyCode == Enum.KeyCode.Q then
			print("Pressed!")
			Ready = false
			Button.BackgroundColor3 = Color3.fromRGB(255,255,255)
			Remote:FireServer(CurrentQ)
			GoOnCooldown(Cooldown)
			Button.Text = "Q"
			Ready = true
		elseif input.UserInputType == Enum.UserInputType.MouseButton1 and ButtonReady == true then
			print("Pressed!")
			Ready = false
			ButtonReady = false
			Button.BackgroundColor3 = Color3.fromRGB(255,255,255)
			Remote:FireServer(CurrentQ)
			GoOnCooldown(Cooldown)
			Button.Text = "Q"
			Ready = true
		elseif input.UserInputType == Enum.UserInputType.Touch and ButtonReady == true then
			print("Pressed!")
			Ready = false
			ButtonReady = false
			Button.BackgroundColor3 = Color3.fromRGB(255,255,255)
			Remote:FireServer(CurrentQ)
			GoOnCooldown(Cooldown)
			Button.Text = "Q"
			Ready = true
		end
	end
end)
2 Likes

occupied is just kinda there and not being set to anything from what im seeing
plus, setting occupied to its value immediately just makes it a boolean value and not be able to be changed externally.

additionally, I believe you could use one boolean too.

local occupied = Frame:WaitForChild("Occupied")
--cooldown function
local function GoOnCooldown(CD:number)
	for i = CD,0,-0.1 do
		Button.Text = math.floor(i*10) / 10
		task.wait(0.1)
	end
       Occupied.Value = false
end

UIS.InputBegan:Connect(function(input, gameProcessed)
     if gameProcessed then return end
     if Occupied.Value == true then return end

     if input.Keycode == Enum.KeyCode.Q then
           print("button pressed!")
           Occupied.Value = true
           GoOnCooldown(Cooldown)
           --other stuff
     end
     --other functions you want
)
2 Likes

Thanks, even though this isn’t technically the solution you gave me a general idea on how to fix it.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.