参数无效#3(期望实例, 得到字符串)
2021-10-8 18:9:13
收藏:0
阅读:140
评论:2
我在搜索引擎中寻找这个问题的解决方案,但找不到一个。
虽然有一个几乎相同的问题,即“参数无效#2(期望字符串,得到实例)”,但我试图用相反的方法修复它,但它使用了tostring()
,而我的问题是关于最新功能:实例属性,它不支持实例作为值,我唯一能做的就是将其转换为字符串,现在问题是关于Part.Parent,它使用Adornee/Instance或者其他我不知道的东西,在此我不知道解决此问题的方法
local LocalPlayer = Players.LocalPlayer;
local Mouse = LocalPlayer:GetMouse();
local function Part_Hide()
if (Toggle_MouseHover == true and Mouse.Target ~= nil) then
if (ReplicatedStorage:FindFirstChild("[Part_Storage]") == nil) then
local Model = Instance.new ("Model", ReplicatedStorage);
Model.Name = "[Part_Storage]";
--Mouse.Target:SetAttribute("Source", Mouse.Target:GetFullName())
Mouse.Target:SetAttribute("Source", Mouse.Target.Name)
Mouse.Target.Parent = Model;
else
local Model = ReplicatedStorage:FindFirstChild("[Part_Storage]");
--Mouse.Target:SetAttribute("Source", Mouse.Target:GetFullName())
Mouse.Target:SetAttribute("Source", Mouse.Target.Name)
Mouse.Target.Parent = Model;
end
end
end
local function Part_Unhide()
if (ReplicatedStorage:FindFirstChild("[Part_Storage]") ~= nil) then
local Storage = ReplicatedStorage:FindFirstChild("[Part_Storage]");
for _, Child in pairs (Storage:GetChildren()) do
--local Source = Child:GetAttribute("Source");
--Child.Parent = Source
Child.Parent = Child:GetAttribute ("Source"); -- <--问题的原因
end
end
end
我不知道是否有一种方法使属性接受实例作为值
“Child.Parent = Child:GetAttribute("Source");”
是否有一种将字符串转换为实例的方法,或将实例保存为值的替代方法,或任何解决此问题的解决方法?如果有,答案将不胜感激,谢谢!
原文链接 https://stackoverflow.com/questions/69499564
点赞
stackoverflow用户13869224
我最终成功让它工作了,谢谢@Kylaaa
结果你的ObjectValue方法真的有效!我正在寻找像这样保留实例值的东西,尽管最后发现了Roblox的最新功能并开始关注它(这是我的第一个错误)
第二个错误是我没有使用别名,因为我认为直接使用实例属性/属性与使用别名后所得到的结果是相同的,别名部分只是装饰或仅添加一行代码的东西(就像使其易于参考的方式)
现在这是完整的代码:
local function Part_Hide()
if (Toggle_MouseHover == true and Mouse.Target ~= nil) then
local Part = Mouse.Target;
local Part_Source = Part.Parent;
local Source = Instance.new ("ObjectValue", Part);
Source.Value = Part_Source;
Source.Name = "Source";
if (ReplicatedStorage:FindFirstChild("[Part_Storage]") == nil) then
local Model = Instance.new ("Model", ReplicatedStorage);
Model.Name = "[Part_Storage]";
Part.Parent = Model;
else
local Model = ReplicatedStorage:FindFirstChild("[Part_Storage]");
Part.Parent = Model;
end
end
end
local function Part_Unhide()
if (ReplicatedStorage:FindFirstChild("[Part_Storage]") ~= nil) then
local Storage = ReplicatedStorage:FindFirstChild("[Part_Storage]");
for _, Child in pairs (Storage:GetChildren()) do
local Source = Child:FindFirstChild("Source");
Child.Parent = Source.Value;
Source:Destroy();
Storage:Destroy();
end
end
end
2021-10-08 19:52:40
评论区的留言会收到邮件通知哦~
推荐文章
- 如何在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 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
- 如何编写 Lua 模式将字符串(嵌套数组)转换为真正的数组?
正如你所指出的那样,实例不适合作为属性类型。
一种解决方法可能是创建一个ObjectValue,并使用它来保存实例的引用。您可以将其放入对象中,然后将其移动到ReplicatedStorage中,然后在从存储中获取时删除它。
local LocalPlayer = Players.LocalPlayer local Mouse = LocalPlayer:GetMouse() -- 如果零件存储容器不存在,请创建它 local PartStorage = ReplicatedStorage:FindFirstChild("[Part_Storage]") if (PartStorage == nil) then PartStorage = Instance.new("Model", ReplicatedStorage) PartStorage.Name = "[Part_Storage]" end local function Part_Hide() if (Toggle_MouseHover == true and Mouse.Target ~= nil) then -- 别名 Mouse Target local Part = Mouse.Target local PartSource = Part.Parent -- 移动零件到存储中 Part.Parent = PartStorage -- 保存到哪里来的引用 local ParentRef = Instance.new("ObjectValue") ParentRef.Value = PartSource ParentRef.Name = "ParentRef" ParentRef.Parent = Part end end local function Part_Unhide() -- 将所有零件移出存储 for _, Child in pairs (PartStorage:GetChildren()) do -- 从子对象中移除 ObjectValue local PartSource = Child:FindFirstChild("ParentRef") PartSource.Parent = nil -- 将子对象放回世界空间中 Child.Parent = PartSource.Value -- 清理 PartSource:Destroy() end end
小提示,除非这是有意的,否则不应在 LocalScript 中执行这些类型的影响世界的操作,因为这些变化只会对拥有 LocalScript 的玩家显示。如果您在服务器端脚本中执行工作,那么所有玩家都会复制这些更改。