如何在没有显示错误的情况下修复我的战斗脚本?
2019-6-25 17:51:46
收藏:0
阅读:78
评论:1
我创建了这个脚本,希望创建一个可以在一个按钮中播放多个动画的战斗系统。然而,当我将它们放入脚本的轻攻击部分时,动画不会播放,但我的代码中没有错误。
我尝试重新组织,使用实际的动画 ID,更改变量名称等。
local Player = game.Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character.Humanoid
AnimationId1 = "rbxassetid://2046787868"
AnimationId2 = "rbxassetid://2046881922"
AnimationId3 = "rbxassetid://"
AnimationId4 = "rbxassetid://2048242167"
Debounce = true
local Key = 'U'
local Key2 = 'I'
local Key3 = 'O'
local Key4 = 'P'
local UserInputService = game:GetService("UserInputService")
--轻攻击连击动画。
UserInputService.InputBegan:connect(function(Input, IsTyping)
for i, v in pairs(game.Players:GetChildren()) do
if Input.KeyCode == Enum.KeyCode[Key] then
local Animation = Instance.new("Animation")
Animation.AnimationId = AnimationId1, AnimationId2
local LoadAnimation = Humanoid:LoadAnimation(Animation)
if v == 1 then
LoadAnimation:Play(AnimationId1)
elseif v == 2 then
LoadAnimation:Play(AnimationId2)
end
end
end
end)
--阻挡动画。
UserInputService.InputBegan:connect(function(Input, IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode[Key4] and Debounce then
Debounce = false
local Animation = Instance.new("Animation")
Animation.AnimationId = AnimationId4
local LoadAnimation = Humanoid:LoadAnimation(Animation)
LoadAnimation:Play()
wait(.5)
LoadAnimation:Stop()
Debounce = true
end
end)
这个脚本的阻挡部分完美地工作,但当我尝试使用轻攻击部分时,它不起作用。
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

在你的轻攻击函数中,
v是一个 Player 对象。所以任何像v == 1或v == 2这样的检查都会失败,因为它是错误的类型。而且当他们按下 'U' 按钮时,你迭代所有玩家也没有意义。你可以像你的阻挡动画代码一样制作一个动画。
-- 制作一个计数器来帮助决定要播放哪个动画 local swingCount = 0 local currentSwingAnimation -- 轻攻击连击序列的动画。 UserInputService.InputBegan:connect(function(Input, IsTyping) if IsTyping then return end if Input.KeyCode == Enum.KeyCode[Key] then swingCount = swingCount + 1 -- 取消当前播放的任何动画 if currentSwingAnimation then currentSwingAnimation:Stop() currentSwingAnimation = nil end if swingCount == 1 then -- 播放第一个动画 local Animation = Instance.new("Animation") Animation.AnimationId = AnimationId1 currentSwingAnimation = Humanoid:LoadAnimation(Animation) currentSwingAnimation.Looped = false currentSwingAnimation:Play() elseif swingCount == 2 then -- 播放第二个动画 local Animation = Instance.new("Animation") Animation.AnimationId = AnimationId2 currentSwingAnimation = Humanoid:LoadAnimation(Animation) currentSwingAnimation.Looped = false currentSwingAnimation:Play() -- 重置摆动计数器以开始新的连击序列 swingCount = 0 end end end)