如何禁用激光而不是启用?(ROBLOX Lua)
2018-7-23 20:25:27
收藏:0
阅读:92
评论:1
嘿stackoverflow社区。所以我开始在ROBLOX中制作"Tycoon"。我收集了一些自定义模型,但我遇到了一个问题。基本上,我想为每个玩家基地设置一个激光门。我遇到的问题是,激光门的激光在游戏开始时就启用了。个人而言,我希望它们在开始时被禁用,以便玩家稍后可以手动启用它们。我遇到问题的原因是因为我不是制作脚本的人,然而,我曾经试图解决它,但是我没有成功。
script.LazerGateLocalScript.LazerGate.Value = script.Parent --设置一个值
local configs = script.Parent.Configurations
local lazers = script.Parent.LazerGate --使其更容易访问这一部分
local lazersOn = true --所以我们知道激光是开启还是关闭
for i, node in pairs(lazers:GetChildren()) do
for i, component in pairs(node:GetChildren()) do
if component.Name == "Emitter" then
local lazerBeam = component:FindFirstChild("ParticleEmitter")
local lazerColor = configs.LazerColor.Value
lazerBeam.Color = ColorSequence.new(lazerColor, lazerColor) --将激光颜色设置为该模型配置中找到的激光颜色
elseif component.Name == "Diode" then
component.BrickColor = configs.DiodeColor.Value
local diodeSparkle = component:FindFirstChild("ParticleEmitter")
diodeSparkle.Color = ColorSequence.new(Color3.new(255,255,255), configs.DiodeSparkleColor.Value)
elseif component.Name == "Lense" then
component.BrickColor = configs.DiodeColor.Value
end
end
end
script.Parent.KillBrick.PointLight.Color = configs.LazerColor.Value
game.Players.PlayerAdded:connect(function(player) -- 当玩家加入时
player.CharacterAdded:connect(function() -- 每当他们的角色被加载时
local newScript = script.LazerGateLocalScript:Clone() -- 克隆本地脚本
newScript.Parent = player.PlayerGui -- 并将其放置在玩家的playerGui中
end)
end)
function lazerToggle(OnOff) -- 此功能仅更改激光的开关状态
for i, node in pairs(lazers:GetChildren()) do
for i, component in pairs(node:GetChildren()) do
if component.Name == "Emitter" then
local lazerBeam = component:FindFirstChild("ParticleEmitter")
if OnOff == true then
lazerBeam.Enabled = true
else
lazerBeam.Enabled = false
end
end
end
end
end
script.Parent.KillBrick.Touched:connect(function(obj)
if obj.Parent and obj.Parent:FindFirstChild("Humanoid") and lazersOn == true then
obj.Parent:BreakJoints()
end
end)
script.Parent.LazerToggle.OnServerEvent:connect(function() -- 当事件被触发时,看看是否要打开或关闭盖子并设置一个值以执行此操作。
if lazersOn == true then
lazerToggle(false)
wait(1.5)
lazersOn = false
else
lazerToggle(true)
wait(0.5)
lazersOn = true
end
end)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:connect(function() -- 如果玩家单击 ...
if script.LazerGate.Value and mouse.Target.Name == "LazerButton" and mouse.Target.Parent.Name == "LazerGateSection" then -- 如果他们点击激光门的按钮
script.LazerGate.Value.LazerToggle:FireServer() -- 触发一个脚本将使用的事件
end
end)
再次说明,我的问题是我想禁用激光,而不是在开始时启用。非常感谢任何帮助!
提前致谢, E.W
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 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 代码?

以下代码应该可以运行:
script.LazerGateLocalScript.LazerGate.Value = script.Parent local configs = script.Parent.Configurations local lazers = script.Parent.LazerGate local lazersOn = false for _, node in pairs(lazers:GetChildren()) do for _, component in pairs(node:GetChildren()) do if component.Name == "Emitter" then local lazerBeam = component:FindFirstChild("ParticleEmitter") local lazerColor = configs.LazerColor.Value lazerBeam.Color = ColorSequence.new(lazerColor, lazerColor) elseif component.Name == "Diode" then component.BrickColor = configs.DiodeColor.Value local diodeSparkle = component:FindFirstChild("ParticleEmitter") diodeSparkle.Color = ColorSequence.new(Color3.new(255,255,255), configs.DiodeSparkleColor.Value) elseif component.Name == "Lense" then component.BrickColor = configs.DiodeColor.Value end end end script.Parent.KillBrick.PointLight.Color = configs.LazerColor.Value game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function() local newScript = script.LazerGateLocalScript:Clone() newScript.Parent = player.PlayerGui end) end) function lazerToggle(OnOff) for _, node in pairs(lazers:GetChildren()) do for _, component in pairs(node:GetChildren()) do if component.Name == "Emitter" then local lazerBeam = component:FindFirstChild("ParticleEmitter") if OnOff then lazerBeam.Enabled = true else lazerBeam.Enabled = false end end end end end script.Parent.KillBrick.Touched:connect(function(obj) if obj.Parent and obj.Parent:FindFirstChild("Humanoid") and lazersOn == true then obj.Parent:BreakJoints() end end) script.Parent.LazerToggle.OnServerEvent:connect(function() if lazersOn == true then lazerToggle(false) wait(1.5) lazersOn = false else lazerToggle(true) wait(0.5) lazersOn = true end end) lazerToggle(false);以上代码放在第一个脚本中,即服务器端脚本,其中有一个名为LazerGateLocalScript的子节点。
local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Button1Down:connect(function() if script.LazerGate.Value and mouse.Target.Name == "LazerButton" and mouse.Target.Parent.Name == "LazerGateSection" then script.LazerGate.Value.LazerToggle:FireServer() end end)然后,以上代码放置在名为LazerGateLocalScript的本地脚本中,该脚本是服务器脚本的子节点。
如果你问,是的,我知道RobloxLua。