You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Roblox Studio中R15角色循环待机动画脚本修复求助

问题分析与修复方案

代码存在的核心问题

  • 角色引用错误:脚本放在Humanoid下,script.Parent指向的是Humanoid对象而非角色模型,后续调用character.Humanoid会试图在Humanoid里找子Humanoid,逻辑完全错误。
  • 动画调用方式错误:Humanoid:PlayAnimation()需要传入Animation对象,而非直接传数字ID;且该方法已被官方标记为过时,推荐使用Humanoid:LoadAnimation()。
  • 无效循环逻辑:每秒重复调用播放会频繁打断动画,导致动画无法正常运行——待机动画本身是循环类型,只需播放一次即可持续运行。

修复后的代码

-- 修正角色引用:Humanoid的父对象才是角色模型
local character = script.Parent.Parent
local humanoid = script.Parent
local animationId = "rbxassetid://12297693014"

-- 创建Animation对象并设置ID
local animation = Instance.new("Animation")
animation.AnimationId = animationId

-- 加载动画并设置循环播放
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack.Looped = true
animationTrack:Play()

额外注意事项

  • 脚本位置优化:虽然放在Humanoid下能运行,但更规范的做法是将本地脚本放在StarterPlayerScripts或StarterCharacterScripts中,避免角色加载时出现引用延迟。
  • 动画权限检查:确保使用的动画ID是公开可使用的,或已添加到你的Roblox资产库中,否则会因权限问题无法播放。

内容的提问来源于stack exchange,提问作者username

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 20:45:41