Lua Tween 部件信息
2021-2-21 17:25:40
收藏:0
阅读:127
评论:1
我正在制作一个 tween,它使用从 Humanoid.Seated 事件获取的数据,并且我想在坐下时让相机到达终点,然后在他们起身后后退。我觉得问题可能出在部件信息上,但我可能错了。
这是代码:
发送器/事件处理程序:
local camPart = script.Parent
local camEvent = game.ReplicatedStorage.CamEvent
local blueSeat = script.Parent.Parent.BlueSeat.Seat --人应该坐在正确的座位上
local bluePlayerName = script.Parent.Parent.Buttons.BlueEnter.PlayerName --人的假定姓名
bluePlayerName:GetPropertyChangedSignal("Value"):Connect(function ()
if (bluePlayerName ~= "") then
local char = game.Workspace:FindFirstChild(bluePlayerName.Value, true)
local player = game.Players:GetPlayerFromCharacter(char)
char.Humanoid.Seated:Connect(function (isSeated, seat)
if (seat.Name == blueSeat.Name) then
camEvent:FireClient(player, camPart, isSeated) --转到 tween 处理程序
end
end)
end
end)
接收器/tween 处理程序:
local TweenService = game:GetService("TweenService")
local cam = game.Workspace.Camera
local partData
local tween
local length = 2
local tweenData = TweenInfo.new(
length,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
true,
0
)
script.Parent.OnClientEvent:Connect(function (camPart, isSeated) --接收器
partData = {
CFrame = camPart.CFrame
}
tween = TweenService:Create(cam, tweenData, partData)
if (isSeated == true) then
cam.CameraType = Enum.CameraType.Scriptable --删除控件
tween:Play()
wait(length / 2)
tween:Pause() --停在终点
elseif (isSeated == false) then
tween:Play() --返回/完成
wait(length / 2)
cam.CameraType = Enum.CameraType.Custom --归还控制
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 代码?

提示 RemoteEvent 没有触发的事实应该表明在服务端脚本中未到达 Humanoid.Seated 事件的连接点。从你提供的代码示例中无法理解何时触发代码,但看起来你只是在等待玩家角色加载到工作区。
我建议使用 Player.CharacterAdded 或者 Player.CharacterAppearanceLoaded 事件来获取玩家的角色和人形。你仍然可以使用你的 UI 代码作为触发器来执行缓动效果,但这样可能更容易。
-- 服务端脚本 local camPart = script.Parent local camEvent = game.ReplicatedStorage.CamEvent local thing = script.Parent.Parent local blueSeat = thing.BlueSeat.Seat -- 应该有人坐的正确座位 local bluePlayerName = thing.Buttons.BlueEnter.PlayerName -- 人名 -- 监听玩家坐在座位上 game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character.Humanoid.Seated:Connect(function(isSeated, seat) print("玩家坐下了?", isSeated) if not isSeated then -- 让客户端缩放镜头 camEvent:FireClient(player, camPart, isSeated) else -- 决定是否缓动镜头 local isApprovedSeat = seat.Name == blueSeat.Name local isNameSet = bluePlayerName.Value ~= "" local shouldTweenCamera = isApprovedSeat and isNameSet if shouldTweenCamera then camEvent:FireClient(player, camPart, isSeated) else local message = table.concat({ "Camera not tweening because: ", "Player has claimed this seat? " .. tostring(hasClaimedSeat), "This is the approved seat? " .. tostring(isApprovedSeat) }, "\n") warn(messsage) end end end) end) end)另外,看起来监听此 RemoteEvent 的 LocalScript 存在于 ReplicatedStorage 中。请查看 LocalScripts 的文档,它们只存在于一些特定位置中,而 ReplicatedStorage 不幸不是其中之一。请将 LocalScript 移到 StarterCharacterScripts 并更新 RemoteEvent 的路径。
local camEvent = game.ReplicatedStorage.CamEvent camEvent.OnClientEvent:Connect(function (camPart, isSeated) -- 接收端