#why does the wrong animation play?

1 messages · Page 1 of 1 (latest)

lethal kettle
#

i was making a simple wallrun system, and when it came to apply animations, the left side animation works, but for some reason it also plays when you are walking on the right side

#

code:

#

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local input = game:GetService("UserInputService")
local runService = game:GetService("RunService")

-- Animaciones
local wallrunAnim = Instance.new("Animation")
wallrunAnim.AnimationId = "rbxassetid://84797440830749"

local wallrunAnim2 = Instance.new("Animation")
wallrunAnim2.AnimationId = "rbxassetid://91746051147886"

local track1, track2

local function loadTracks()
track1 = animator:LoadAnimation(wallrunAnim)
track2 = animator:LoadAnimation(wallrunAnim2)
end

loadTracks()

-- Variables
local root = character:FindFirstChild("HumanoidRootPart") or character:FindFirstChild("Torso")
local wallBV : BodyVelocity?
local distance = 5
local speed = 32
local iswallrunning = false
local onCooldown = false
local cooldownTime = 0.5

-- Recarga al respawn
player.CharacterAdded:Connect(function(newchar)
character = newchar
humanoid = character:WaitForChild("Humanoid")
root = character:FindFirstChild("HumanoidRootPart") or character:FindFirstChild("Torso")
animator = humanoid:WaitForChild("Animator")
loadTracks()
end)

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {character}

local function getwallrunningdirection(forward, normal)
local dir = (forward - forward:Dot(normal) * normal)
return dir.Unit
end

#

local function startwallrunning(wallhit, wallside)
if iswallrunning or onCooldown then return end
iswallrunning = true

wallBV = Instance.new("BodyVelocity")
wallBV.MaxForce = Vector3.new(1, 1, 1) * 30000
wallBV.Parent = root

local forward = root.CFrame.LookVector
local normal = wallhit.Normal
local rundir = getwallrunningdirection(forward, normal)
wallBV.Velocity = Vector3.new(rundir.X * speed, -4, rundir.Z * speed)

print("Wallrun iniciado en:", wallhit.Instance.Name, "lado:", wallside)
if wallside == "leftwall" and track1 then
    track1:Play()
elseif wallside == "rightwall" and track2 then
    track2:Play()
end

end

local function stopwallrunning()
if not iswallrunning then return end
if track1 then track1:Stop() end
if track2 then track2:Stop() end
iswallrunning = false
if wallBV then
wallBV:Destroy()
wallBV = nil
end
print("Wallrun detenido")

onCooldown = true
task.delay(cooldownTime, function()
    onCooldown = false
end)

end

-- Toggle con barra espaciadora
input.InputBegan:Connect(function(key, gp)
if gp then return end
if key.KeyCode == Enum.KeyCode.Space then
if iswallrunning then
stopwallrunning()
else
local leftwall = workspace:Raycast(root.Position, root.CFrame.RightVector * -distance, params)
local rightwall = workspace:Raycast(root.Position, root.CFrame.RightVector * distance, params)

        local wallhit, wallside
        if rightwall and rightwall.Instance:HasTag("wallrun") then
            wallhit = rightwall
            wallside = "rightwall"
        elseif leftwall and leftwall.Instance:HasTag("wallrun") then
            wallhit = leftwall
            wallside = "leftwall"
        end

        if wallhit then
            startwallrunning(wallhit, wallside)
        end                  
    end
end

end)

#

-- Cancela al tocar suelo
humanoid.StateChanged:Connect(function(_, newState)
if newState == Enum.HumanoidStateType.Landed or newState == Enum.HumanoidStateType.Running then
stopwallrunning()
end
end)

-- Cancela si deja de detectar pared
runService.Heartbeat:Connect(function()
if iswallrunning then
local leftwall = workspace:Raycast(root.Position, root.CFrame.RightVector * -distance, params)
local rightwall = workspace:Raycast(root.Position, root.CFrame.RightVector * distance, params)
local wallhit = rightwall or leftwall

    if not (wallhit and wallhit.Instance:HasTag("wallrun")) then
        stopwallrunning()
    end
end

end)

sour temple
#

maybe try printing whenever the animations play to debug whether if its being overriden or a logic issue

lethal kettle
#

if i remove the left animation, the right works properly

#

wait, i think the animation IDs are the issue

#

i changed the right one to the left one (the id of the previously track 1 is 2) but the same animation plays