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)