Roblox脚本报错:argument 2 missing or nil,求技术解决方案
Roblox脚本报错"argument 2 missing or nil"排查与修复
问题根源
1. tweenInfoPopups变量未定义
报错指向的tweenService:Create方法第二个参数是tweenInfoPopups,但你的脚本中完全没有定义这个变量。TweenService:Create的第二个参数必须是一个**TweenInfo对象**,用于指定动画的时长、缓动方式等核心属性,缺失或未定义就会触发argument 2 missing or nil错误。
2. 额外语法错误
脚本中第二行补间创建代码存在语法错误:
tweenService:Create(script.Parent.Parent.Title. tweenInfoPopups, {Position = UDim2.new(0.5,0,-1.25,0)}):Play()
这里script.Parent.Parent.Title.后面多了一个点和空格,正确写法应该用逗号分隔参数:script.Parent.Parent.Title, tweenInfoPopups
3. 方法调用错误
最后一行的script.Parent.Parent.Parent.Destroy()写法错误,Destroy是Instance类的方法,需要用冒号调用::Destroy()
修复后的完整脚本
-- 先获取TweenService服务并定义补间参数 local tweenService = game:GetService("TweenService") local tweenInfoPopups = TweenInfo.new( 1, -- 动画时长(秒) Enum.EasingStyle.Quad, -- 缓动样式(可根据需求修改) Enum.EasingDirection.Out, -- 缓动方向(可根据需求修改) 0, -- 重复次数 false, -- 是否反向播放 0 -- 延迟时间(秒) ) script.Parent.Play.TextButton.MouseButton1Click:Connect(function() script.Enabled = false for i, v in pairs(script.Parent:GetDescendants()) do if v:IsA("TextButton") then v.Visible = false end end tweenService:Create(script.Parent, tweenInfoPopups, {Position = UDim2.new(0.5,0,1.25,0)}):Play() tweenService:Create(script.Parent.Parent.Title, tweenInfoPopups, {Position = UDim2.new(0.5,0,-1.25,0)}):Play() tweenService:Create(script.Parent.Parent.Parent.Transition, tweenInfoPopups, {Position = UDim2.new(0,0,.5,0)}):Play() wait(1) script.Parent.Parent.Parent.CameraScript.Enabled = false game.Workspace.Camera.CameraType = Enum.CameraType.Custom tweenService:Create(script.Parent.Parent.Parent.Transition, tweenInfoPopups, {Position = UDim2.new(-1,0,.5,0)}):Play() wait(1) script.Parent.Parent.Parent:Destroy() end)
内容的提问来源于stack exchange,提问作者Shsbsbss
相关产品推荐
相关产品推荐

