#Character.Changed Function not working

1 messages · Page 1 of 1 (latest)

hollow kite
#

Ive been trying to cancel the sprint state when you attack while sprinting, but the character.Changed function WILL not work

#

@atomic nest sorry for ping but i really need to solve this

atomic nest
#

Its ok, I'll see

#

give me a while

#

Wait

molten adderBOT
#

studio** You are now Level 8! **studio

atomic nest
#

Character.Changed only fires for property changes directly on the Character model itself.
It does not detect child changes, nor actions like attacks, nor state changes like Humanoid.State.

#

**If you want to cancel sprinting when the player attacks, you need to listen to something that actually changes when attacking.
Depending on your game setup, attacks can trigger:

  • Tool .Activated event (if using tools)

  • Animation playing events

  • Mouse click events

  • Or a custom RemoteEvent**

#

I'll code u a script fix the problem

hollow kite
#

ok

atomic nest
#

Detect Attacks Properly

local tool = chr:FindFirstChildOfClass("Tool")
if tool then
    tool.Activated:Connect(function()
        if issprinting then
            togglesprint()
        end
    end)
end
#

ig its good

hollow kite
#

its not a tool tho

#

unfortunately

#

i didnt go tools for combat

#

E to equip

#

;-;

atomic nest
#

In your onkeypressed function, add this:

if key.KeyCode == Enum.KeyCode.E then
    if issprinting then
        togglesprint()
    end
    -- Equip logic...
end
hollow kite
#

i have a function like that]

atomic nest
#

This will Cancel Sprint When Equipping (E key):

molten adderBOT
#

studio** You are now Level 5! **studio

hollow kite
#

it detects the attribute

#
chr:GetAttributeChangedSignal("Equipped"):Connect(function()
    if not issprinting then
    selectanim("Walk")
    else
        selectanim("Sprint")
    end
end)```
atomic nest
#

You're using a character attribute called "Equipped" to control the equip state

#

So now the goal is:
Cancel sprint immediately if "Equipped" changes to true (or 1, or anything truthy).
Is true?

hollow kite
#

i wanna cancel the sprint when you attack

#

when you equip, it changes your animation to the set weapon sprint animation

#

if that makes sense

atomic nest
#

give me a while, I'll code u a good & working script + comments, to understand the code perfectly!!

hollow kite
#

ok

atomic nest
#
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local isSprinting = false
local equipped = false

local sprintAnim = humanoid:LoadAnimation(script:WaitForChild("SprintAnim")) -- Your normal sprint anim
local weaponSprintAnim = humanoid:LoadAnimation(script:WaitForChild("WeaponSprintAnim")) -- Sprint with weapon anim

local function startSprint()
    if not equipped then
        sprintAnim:Play()
        isSprinting = true
    end
end

local function stopSprint()
    sprintAnim:Stop()
    weaponSprintAnim:Stop()
    isSprinting = false
end

local function onEquip()
    equipped = true
    if isSprinting then
        sprintAnim:Stop()
    end
    weaponSprintAnim:Play()
    isSprinting = true
end

local function onUnequip()
    equipped = false
    weaponSprintAnim:Stop()
    isSprinting = false
end

local function onAttack()
    if isSprinting then
        stopSprint()
    end
end

-- Bind the Equip event, for example using a RemoteEvent or attribute change
player:GetAttributeChangedSignal("Equipped"):Connect(function()
    if player:GetAttribute("Equipped") then
        onEquip()
    else
        onUnequip()
    end
end)

-- Bind attack input (example: when player clicks mouse or presses attack key)
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        onAttack()
    end
end)

-- Example sprint toggle (shift key)
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end
    if input.KeyCode == Enum.KeyCode.LeftShift then
        if isSprinting then
            stopSprint()
        else
            startSprint()
        end
    end
end)
#

here we go, oh my hands

hollow kite
#

ty