Roblox脚本不再存在于游戏中,但出现在新创建的角色中
2018-12-9 3:44:23
收藏:0
阅读:98
评论:1
我在使用从Roblox市场中下载的脚本并对其进行了大幅修改。原始版本已不再存在于游戏中,但出现在新角色的子级中,尽管我没有脚本可以将其放置在那里。为什么会这样发生,我该如何修复?我在任何其他地方都没有发现类似的情况。
以下是原始脚本:
local mouse = game.Players.LocalPlayer:GetMouse()
local running = false
function getTool()
for _, kid in ipairs(script.Parent:GetChildren()) do
if kid.className == "Tool" then return kid end
end
return nil
end
mouse.KeyDown:connect(function (key) -- Run function
key = string.lower(key)
if string.byte(key) == 48 then
running = true
local keyConnection = mouse.KeyUp:connect(function (key)
if string.byte(key) == 48 then
running = false
end
end)
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
wait()
end
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 85
repeat wait () until running == false
keyConnection:disconnect()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
wait()
end
end
end)
以下是修改后的脚本:
wait(1)
local Player = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local running = false
local startSpeed = 10
local Speed = script.Speed
Speed.Value = 10
local Earnings = script.Earnings
Earnings.Value = 25
local Cash = script.Cash
Cash.Value = 10000
local speedUpCost = script.speedUpCost
speedUpCost.Value = 100
local earnUpCost = script.earnUpCost
earnUpCost.Value = 100
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = Speed.Value
function getTool()
for _, kid in ipairs(script.Parent:GetChildren()) do
if kid.className == "Tool" then return kid end
end
return nil
end
mouse.KeyDown:connect(function (key)
key = string.lower(key)
if string.byte(key) == 48 then
running = true
local keyConnection = mouse.KeyUp:connect(function (key)
if string.byte(key) == 48 then
running = false
end
end)
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = Speed.Value
repeat wait () until running == false
keyConnection:disconnect()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = startSpeed
end
end)
以下是我使用的代码,将修改后的脚本和其他一些脚本作为新角色的子级:(这些其他脚本不包括我修改的原始脚本)
function onPlayerEntered(player)
player.CharacterAdded:connect(function (char)
local Scripts = script:GetChildren()
for i=1,5 do
local s = Scripts[i]:clone()
s.Parent = char
s.Disabled = false
end
end)
end
game.Players.PlayerAdded:connect(onPlayerEntered)
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 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 代码?

不知道你的 explorer 中有哪些脚本,但看起来你的问题可能出在 onPlayerEntered 函数中。你正在遍历 5 个未命名、可能是随机的脚本,并将它们插入到玩家中。
根据 https://developer.roblox.com/api-reference/function/Instance/GetChildren 中的说明,
script:GetChildren()中元素的顺序取决于它们 Parent 属性的设置顺序。最好通过名称显式克隆子元素,或者遍历脚本数组的长度。为了调试该问题,我建议修改你的循环:
local Scripts = script:GetChildren() for i=1,#Scripts,1 do local s = Scripts[i]:clone() s.Parent = char s.Disabled = false print("Inserting script : ", s.Name, " - ", s:GetFullName()) end这应该可以告诉你哪些脚本实际上被添加了。
或者,你可以将你想要添加的脚本添加到
StarterPlayer > StarterPlayerScripts文件夹中,当玩家加入游戏时,它们将自动添加到玩家中。