Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Sword ability spammable after first use?

Asked by 2 years ago
Edited 2 years ago

Hi, I'm making a sword PVP game where each sword has an ability. The thing is though, every sword ability is spammable! I've tested it out with my friends and they can keep spamming the abilities even when there's clearly a cooldown. Help would be much appreciated!

Here is the first script: (Local script inside the sword)

local UIS = game:GetService("UserInputService")
local tool = script.Parent
local player = game.Players.LocalPlayer
local enabled = false
local remote = game:GetService("ReplicatedStorage"):FindFirstChild("NormalSlash")
local ready = true
local debounce = false

tool.Equipped:Connect(function()
        enabled = true

    end)
tool.Unequipped:Connect(function()
        enabled = false

end)

repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local anim = Instance.new("Animation")
anim.AnimationId = "https://www.roblox.com/asset/?id=8446540208"

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        local playAnim = humanoid:LoadAnimation(anim)
        if not debounce then
            debounce = true
            if enabled == true then
                remote:FireServer()
                playAnim:Play()
            end
        end
        wait(5)
        debounce = false
    end
end)

Here is the 2nd script: (A script inside ServerScriptService)

local damage = 0.25

local StartColor = Color3.new(255,255,0)
local EndColor = Color3.new(255,255,255)

local sequence = ColorSequence.new(StartColor, EndColor)

local sequence2 = ColorSequence.new(EndColor)

game.ReplicatedStorage.NormalSlash.OnServerEvent:Connect(function(player)
    local char = player.Character
    local Sword = char:WaitForChild("Sword")
    Sword.Handle.BrickColor = BrickColor.new("New Yeller")
    Sword.Handle.Wedge1.BrickColor = BrickColor.new("New Yeller")
    Sword.Handle.Wedge2.BrickColor = BrickColor.new("New Yeller")
    Sword.Handle.Material = "Neon"
    Sword.Handle.Wedge1.Material = "Neon"
    Sword.Handle.Wedge2.Material = "Neon"
    Sword.Handle.SlashTrail.Color = sequence
    Sword.Handle.MegaSlash:Play()
    Sword.Handle.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            if hit.Parent.Name ~= player.Name then
                hit.Parent.Humanoid:TakeDamage(damage)
            end
        end
    end)
    wait(1)
    Sword.Handle.BrickColor = BrickColor.new("Medium stone grey")
    Sword.Handle.Wedge1.BrickColor = BrickColor.new("Medium stone grey")
    Sword.Handle.Wedge2.BrickColor = BrickColor.new("Medium stone grey")
    Sword.Handle.Material = "Plastic"
    Sword.Handle.Wedge1.Material = "Plastic"
    Sword.Handle.Wedge2.Material = "Plastic"
    Sword.Handle.SlashTrail.Color = sequence2
    wait(4)
end)
0
Perhaps this is because the script is running whenever someone presses E, if they press E before the script is done running it will run again AnimeAdiction2 0 — 2y

Answer this question