#How can I disable jump while doing m1s and also 0.5 seconds after each m1.

22 messages · Page 1 of 1 (latest)

brisk steeple
#
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local animationFolder = game:WaitForChild("ReplicatedStorage"):WaitForChild("BasicCombat"):WaitForChild("Animations")
local currentAnimation = 1
local comboCount = 0
local canClick = true
local comboDelay = 1

local character = game.Players.LocalPlayer.Character
local humanoid = character:WaitForChild("Humanoid")

local isToolEquipped = false
local button1DownConnection = nil

local function playNextAnimation()
    if not isToolEquipped or not canClick then
        return
    end

    local animation = animationFolder:FindFirstChild(tostring(currentAnimation))
    if animation then
        local animationTrack = humanoid:LoadAnimation(animation)
        animationTrack:Play()

        animationTrack.Stopped:Connect(function()
            currentAnimation = (currentAnimation % 5) + 1
            comboCount = comboCount + 1

            if comboCount >= 5 then
                comboCount = 0
                canClick = false

                wait(comboDelay)

                canClick = true
            else
                canClick = true
            end
        end)

        canClick = false
    end
end

local function onToolEquipped(child)
    if child:IsA("Tool") and child.Name == tool.Name then
        isToolEquipped = true
        button1DownConnection = mouse.Button1Down:Connect(playNextAnimation)
    end
end

local function onToolUnequipped(child)
    if child:IsA("Tool") and child.Name == tool.Name then
        isToolEquipped = false
        if button1DownConnection then
            button1DownConnection:Disconnect()
            button1DownConnection = nil
        end
    end
end

character.ChildAdded:Connect(onToolEquipped)
character.ChildRemoved:Connect(onToolUnequipped)
#

I dont want the user that is punching to be able to jump while doing m1s and also 0.5 seconds after each punch.

narrow spoke
#

the simplest solution would be to just set the JumpPower to 0 for a set duration and then set it back to default. But that might cause problems if you have something in your game that modifies your JumpPower.

brisk steeple
narrow spoke
#

fire the event again to enable it

#

or just pass in the disable time in the event

brisk steeple
#

@narrow spoke I tried doing something like this and it doesnt work.
luascript : ```lua
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local animationFolder = game:WaitForChild("ReplicatedStorage"):WaitForChild("BasicCombat"):WaitForChild("Animations")
local currentAnimation = 1
local comboCount = 0
local canClick = true
local comboDelay = 1

local character = game.Players.LocalPlayer.Character
local humanoid = character:WaitForChild("Humanoid")

local isToolEquipped = false
local button1DownConnection = nil

local function disableJumpState()
if not game.Players.LocalPlayer:GetAttribute("IsJumpDisabled") then
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
end

local function enableJumpState()
if game.Players.LocalPlayer:GetAttribute("IsJumpDisabled") then
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end

local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local RemotesFolder = ReplicatedStorage:WaitForChild("Remotes")
local remoteEvent = RemotesFolder:WaitForChild("ToggleJumpState")

remoteEvent.OnClientEvent:Connect(function(action)
if action == "DisableJump" then
disableJumpState()
elseif action == "EnableJump" then
enableJumpState()
end
end)

local function playNextAnimation()
if not isToolEquipped or not canClick then
return
end

local animation = animationFolder:FindFirstChild(tostring(currentAnimation))
if animation then
    local animationTrack = humanoid:LoadAnimation(animation)
    animationTrack:Play()

    animationTrack.Stopped:Connect(function()
        currentAnimation = (currentAnimation % 5) + 1
        comboCount = comboCount + 1
        if comboCount >= 5 then
            comboCount = 0
            canClick = false

            wait(comboDelay)

            canClick = true
        else
            canClick = true
        end
    end)

    canClick = false
end

end

local function onToolEquipped(child)
if child:IsA("Tool") and child.Name == tool.Name then
isToolEquipped = true
button1DownConnection = mouse.Button1Down:Connect(playNextAnimation)
end
end

local function onToolUnequipped(child)
if child:IsA("Tool") and child.Name == tool.Name then
isToolEquipped = false
if button1DownConnection then
button1DownConnection:Disconnect()
button1DownConnection = nil
end
end
end

character.ChildAdded:Connect(onToolEquipped)
character.ChildRemoved:Connect(onToolUnequipped)


server script : ```lua
-- Server script to handle the remote event
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local RemotesFolder = ReplicatedStorage:WaitForChild("Remotes")
local remoteEvent = RemotesFolder:WaitForChild("ToggleJumpState")

local function handleToggleJumpState(player, action)
    if action == "DisableJump" then
        player:SetAttribute("IsJumpDisabled", true)
    elseif action == "EnableJump" then
        player:SetAttribute("IsJumpDisabled", false)
    end
end

remoteEvent.OnServerEvent:Connect(handleToggleJumpState)
narrow spoke
#

ah you dont need to involve any attributes in this

#

also where exactly are you firing the remote event of the clien

#

alright you dont need any remotes for this since you are already handling the combat on the client nvm

#
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local animationFolder = game:WaitForChild("ReplicatedStorage"):WaitForChild("BasicCombat"):WaitForChild("Animations")
local currentAnimation = 1
local comboCount = 0
local canClick = true
local comboDelay = 1

local character = game.Players.LocalPlayer.Character
local humanoid = character:WaitForChild("Humanoid")

local isToolEquipped = false
local button1DownConnection = nil

local function JumpState(state)
      humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, state)
end

local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local RemotesFolder = ReplicatedStorage:WaitForChild("Remotes")
local remoteEvent = RemotesFolder:WaitForChild("ToggleJumpState")

#
remoteEvent.OnClientEvent:Connect(function(action)
    JumpState(action)
end)

local function playNextAnimation()
    if not isToolEquipped or not canClick then
        return
    end

    local animation = animationFolder:FindFirstChild(tostring(currentAnimation))
    if animation then
        local animationTrack = humanoid:LoadAnimation(animation)
        animationTrack:Play()

        animationTrack.Stopped:Connect(function()
            currentAnimation = (currentAnimation % 5) + 1
            comboCount = comboCount + 1
            if comboCount >= 5 then
                comboCount = 0
                canClick = false

                wait(comboDelay)

                canClick = true
            else
                canClick = true
            end
        end)

        canClick = false
    end
end

local function onToolEquipped(child)
    if child:IsA("Tool") and child.Name == tool.Name then
        isToolEquipped = true
        button1DownConnection = mouse.Button1Down:Connect(playNextAnimation)
    end
end

local function onToolUnequipped(child)
    if child:IsA("Tool") and child.Name == tool.Name then
        isToolEquipped = false
        if button1DownConnection then
            button1DownConnection:Disconnect()
            button1DownConnection = nil
        end
    end
end

character.ChildAdded:Connect(onToolEquipped)
character.ChildRemoved:Connect(onToolUnequipped)
#

change the local script with this ^

#
-- Server script to handle the remote event
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local RemotesFolder = ReplicatedStorage:WaitForChild("Remotes")
local remoteEvent = RemotesFolder:WaitForChild("ToggleJumpState")

local function handleToggleJumpState(player, action)
    remoteEvent:FireClient(player,action)
end
#

and the server script with this ^

#

now all you need to do is use the handleToggleJumpState function

#

action is either false or true

#

its a bool

#

imma sleep now I'll check in tomorrow

brisk steeple
#

yea it doesnt change anything the jump is still not disabled.