如何在此roblox lua脚本中修复多人游戏?

时间:2019-11-16 15:32:39

标签: lua scripting roblox

我的脚本仅传送并把工具提供给一位玩家。 即使我将i = 1更改为一个更大的数字,它也只是从一定数量的人开始玩迷你游戏,并且与i = 1做同样的事情。我在网上查找了该游戏,并问了其他开发者我知道,他们无法解决,所以我问你们。 请尝试帮助我...

while true do 
  wait(5) 
  local m = math.random(1,6)
  local g = math.random(1,4)
  local player = game.Players:GetChildren()
  for i = 1, #player do 
    msg = Instance.new("Message") 
    msg.Parent = nil 
    --Minigame1
    msg.Parent = game.Workspace 
    msg.Text = "Choosing Map."
    wait(0.5)
    msg.Text = "Choosing Map.."
    wait(0.5)
    msg.Text = "Choosing Map..."
    wait(0.5)
    msg.Text = "Choosing Map."
    wait(0.5)
    msg.Text = "Choosing Map.."
    wait(0.5)
    msg.Text = "Choosing Map..."
    wait(0.5)
    msg.Text = "Choosing Map."
    wait(0.5)
    msg.Text = "Choosing Map.."
    wait(0.5)
    msg.Text = "Choosing Map..."
    wait(0.5)
    msg.Text = "Map Number" ..m.. "!!!" 
    wait(3)
    msg.Text = game.Lighting.Minigames["Minigame"..m].MapName.Value
    wait(3)
    msg.Text = game.Lighting.Minigames["Minigame"..m].Description.Value
    wait(3)
    game.Lighting.Minigames["Minigame"..m]:clone().Parent = game.Workspace 
    wait(3)
    player[i].Character:MoveTo(Vector3.new(-24.19, 1, -14.69))
    msg.Text = "Choosing Minigame."
    wait(0.5)
    msg.Text = "Choosing Minigame.."
    wait(0.5)
    msg.Text = "Choosing Minigame..."
    wait(0.5)
    msg.Text = "Choosing Minigame."
    wait(0.5)
    msg.Text = "Choosing Minigame.."
    wait(0.5)
    msg.Text = "Choosing Minigame..."
    wait(0.5)
    msg.Text = "Choosing Minigame."
    wait(0.5)
    msg.Text = "Choosing Minigame.."
    wait(0.5)
    msg.Text = "Choosing Minigame..."
    wait(0.5)
    msg.Text = game.Lighting.Minigames["Minigame"..m]["Mode"..g].Value
    wait(2)
    msg.Text = game.Lighting.Minigames["Minigame"..m]["ModeDescription"..g].Value
    wait(5)
    msg:remove() 
    game.Lighting.Minigames["Minigame"..m]["Tool"..g]:Clone().Parent = 
    player[i].Backpack
    wait(60)
    msg.Parent = game.Workspace
    msg.Text = "GAME END"
    wait(3)
    player[i].Character:MoveTo(Vector3.new(-168.742, 148.7, -26.169))
    msg:remove() 
    game.Workspace["Minigame"..m]:Destroy() 
    if player[i].Backpack:FindFirstChild("Tool1") or 
        player[i].Backpack:FindFirstChild("Tool2") or 
        player[i].Backpack:FindFirstChild("Tool3") or 
        player[i].Backpack:FindFirstChild("Tool4") then
      player[i].Backpack.Tool1:Remove()  
      player[i].Backpack.Tool2:Remove()
      player[i].Backpack.Tool3:Remove()
      player[i].Backpack.Tool4:Remove()
    end
    if player[i].Character:FindFirstChild("Tool"..g) then
      player[i].Character.Tool1:Destroy()
      player[i].Character.Tool2:Destroy()
      player[i].Character.Tool3:Destroy()
      player[i].Character.Tool4:Destroy()
    end
  end
end

1 个答案:

答案 0 :(得分:0)

此脚本有很多问题,但是我只关注那些可以立即解决您问题的脚本-如果您想清理代码,请转到Code Review

local player = game.Players:GetChildren()
--code here
for i = 1, #player do
  player[i].Character:MoveTo(Vector3.new(-24.19, 1, -14.69))
  game.Lighting.Minigames["Minigame"..m]["Tool"..g]:Clone().Parent = 
  player[i].Backpack
end
--more code would go here
for i = 1, #player do
  player[i].Character:MoveTo(Vector3.new(-168.742, 148.7, -26.169))
  if player[i].Backpack:FindFirstChild("Tool1") or 
      player[i].Backpack:FindFirstChild("Tool2") or 
      player[i].Backpack:FindFirstChild("Tool3") or 
      player[i].Backpack:FindFirstChild("Tool4") then
    player[i].Backpack.Tool1:Remove()  
    player[i].Backpack.Tool2:Remove()
    player[i].Backpack.Tool3:Remove()
    player[i].Backpack.Tool4:Remove()
  end
  if player[i].Character:FindFirstChild("Tool"..g) then
    player[i].Character.Tool1:Destroy()
    player[i].Character.Tool2:Destroy()
    player[i].Character.Tool3:Destroy()
    player[i].Character.Tool4:Destroy()
  end
end

这是for循环中唯一的内容。其余的应该只运行一次,因此,不应在for循环内-因此,我在其余代码应位于的地方(为了节省空间)添加了注释,只保留了应包含的内容被循环。

您的问题是您正在分别为每个玩家运行所有消息和wait命令。根据游戏中玩家的数量,您将有多个循环,但是没有一个循环可以同时运行,因此您需要遍历整个玩家的脚本,依次为玩家1,玩家2,玩家3。由于您的游戏似乎只有持续60秒的回合,这意味着玩家1获得回合的工具,然后玩家2获得回合的工具,然后玩家3获得回合的工具,等等。

如果您将所有这些移出循环(如我上面所述),而只留下移动播放器并破坏其工具的部分(但不添加它们呢?似乎缺少代码),则该代码应该可以正常工作很好。