Need help saving & changing WalkSpeed

BlockEvent.OnServerEvent:Connect(function(plr, isBlocking)
    -- Variables
    local Character = plr.Character
    local Humanoid = Character.Humanoid
    local blockAnim = Humanoid.Animator:LoadAnimation(blockAnimations[1])
    
    local currSpeed = Humanoid.WalkSpeed
    local currJump = Humanoid.JumpPower
    
    print(currJump)
    print(currSpeed)
    
    if isBlocking then
        print("Started Blocking")
        blockAnim:Play()
        
        Humanoid.WalkSpeed = 6
        Humanoid.JumpPower = 6
        
        print(currJump)
        print(currSpeed)
        local blockAction = Instance.new("NumberValue") blockAction.Parent = Humanoid
        blockAction.Name = "blockAction"
        blockAction.Value = 5
        
    elseif not isBlocking then
        print("Stopped Blocking")
        
        print(currJump)
        print(currSpeed)
        Humanoid.WalkSpeed = currSpeed
        Humanoid.JumpPower = currJump

        -- Attempts to stop the blocking animation.
        for i, anims in pairs(Humanoid:GetPlayingAnimationTracks()) do
            if anims.Name == "Block" then
                anims:Stop()
            end
        end
        
        
        local blockAction = Humanoid:FindFirstChild("blockAction")
        if blockAction then
            blockAction:Destroy()
        end
    end
    
    BlockEvent:FireClient(plr)
end)

So basically when you block for the first time, it saves the correct walkspeed and jump data, however, when you unblock, the remote event is fired again and will change the walkspeed/jump data values (currSpeed, currJump) to the blocking speed and I don’t want it to do that, any ideas?

1 Like

Wait nevermind try adding another value that saves the old walkspeed but doesn’t overwrite

When the remote event is fired and they’re not blocking, it saves it’s normal movement speed. However, the same remote event is fired when they unblock, causing the script to set its currspeed and currjump to the block speed.
A possible solution to this would be

BlockEvent.OnServerEvent:Connect(function(plr, isBlocking)
    -- Variables
    local Character = plr.Character
    local Humanoid = Character.Humanoid
    local blockAnim = Humanoid.Animator:LoadAnimation(blockAnimations[1])
    
    local currSpeed = 16
    local currJump = 20 —I don’t actually know the default jump height
    
    print(currJump)
    print(currSpeed)
    
    if isBlocking then
        print("Started Blocking")
        blockAnim:Play()
        
        Humanoid.WalkSpeed = 6
        Humanoid.JumpPower = 6
        
        print(currJump)
        print(currSpeed)
        local blockAction = Instance.new("NumberValue") blockAction.Parent = Humanoid
        blockAction.Name = "blockAction"
        blockAction.Value = 5
        
    elseif not isBlocking then
        print("Stopped Blocking")
        
        print(currJump)
        print(currSpeed)
        Humanoid.WalkSpeed = currSpeed
        Humanoid.JumpPower = currJump

        -- Attempts to stop the blocking animation.
        for i, anims in pairs(Humanoid:GetPlayingAnimationTracks()) do
            if anims.Name == "Block" then
                anims:Stop()
            end
        end
        
        
        local blockAction = Humanoid:FindFirstChild("blockAction")
        if blockAction then
            blockAction:Destroy()
        end
    end
    
    BlockEvent:FireClient(plr)
end)

I made something which handles WalkSpeed using modifiers you can add to the player. I’ll probably release an official version later, but this might be helpful to you in this situation:

I’d recommend adding a “Blocking” modifier with the amount of speed difference (it can be negative) that you want to slow them down by. Hope it helps!