#Character.Changed Function not working
1 messages · Page 1 of 1 (latest)
** You are now Level 8! **
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
ok
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
In your onkeypressed function, add this:
if key.KeyCode == Enum.KeyCode.E then
if issprinting then
togglesprint()
end
-- Equip logic...
end
i have a function like that]
This will Cancel Sprint When Equipping (E key):
** You are now Level 5! **
it detects the attribute
chr:GetAttributeChangedSignal("Equipped"):Connect(function()
if not issprinting then
selectanim("Walk")
else
selectanim("Sprint")
end
end)```
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?
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
give me a while, I'll code u a good & working script + comments, to understand the code perfectly!!
ok
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
ty