我的脚本只将工具传送给一个玩家。即使我把i = 1改成一个更高的数字,它也只是用这么多人开始玩小游戏,做的事情和i = 1一样,.I已经在网上查过了,我问过我认识的其他开发人员,他们都不能解决这个问题,所以我问你们。请尝试帮助我..。
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发布于 2019-11-19 19:08:18
这个脚本有很多问题,但我只会关注那些能立即帮助您解决问题的问题--如果您想要清理代码,请转到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获得了一轮的工具,依此类推。
如果你像我上面那样把所有这些都移出循环,只留下移动玩家和销毁他们工具的部分(但不要添加他们?似乎缺少代码),代码应该可以正常运行。
https://stackoverflow.com/questions/58892307
复制相似问题