So I am making a mini game and I can't get this script to work
Errors at Line 12
local Map = "WaterRun"; local Time = script.Parent.Time; local function Intermission(player) for t = 30, 1, -1 do Time.Text = t; wait(1); end for i,v in pairs(game.Players:GetChildren()) do if (Map == "WaterRun") then v:GetPlayerFromCharacter(player); player.Parent.HumanoidRootPart.CFrame = CFrame.new(-207.5, 15.5, 151.5); end end end script.Parent.StartRound.MouseButton1Click:Connect(Intermission);
https://developer.roblox.com/articles/For-Loops (don't know why you need this, but if it answers your title, there it is) as for your description, this should help you:
local Map = "WaterRun"; local Time = script.Parent.Time; local function Intermission(player) for t = 30, 1, -1 do Time.Text = t; wait(1); end for i,v in pairs(game.Players:GetChildren()) do if (Map == "WaterRun") then --this is always going to be true, why have this if statement if it will always run? v.Character.HumanoidRootPart.CFrame = CFrame.new(-207.5, 15.5, 151.5); elseif (Map == "Future maps" then--just added this for you so you know what to do for future maps end end end script.Parent.StartRound.MouseButton1Click:Connect(Intermission);
So I don't understand why your question was about counting down, but the error at line 12 should be fixed by using v, the player and getting the humanoid root part of that player.
The For Loop syntax is for init, max/min value, increment
. Instead of creating a new variable and decrementing from it, you can simply do it inside the for loop.
local Map = "WaterRun"; local Time = script.Parent.Time; local Pos = CFrame.new(-207.5, 15.5, 151.5); local function Intermission() for t = 30, 1, -1 do Time.Text = t; wait(1); end for _, plr in pairs(game.Players:GetPlayers()) do if (Map == "WaterRun") then plr.Character.HumanoidRootPart.CFrame = Pos; end end end script.Parent.StartRound.MouseButton1Click:Connect(Intermission);
Once you started adding in more maps, you will notice that conditional statements are very frustrating to use. To counter that, saving it in a table saves you great deal of time.
local Maps = { ["WaterMap"] = CFrame.new(100, 100, 100); ["AnotherMap"] = CFrame.new(200, 200, 200); } local Time = script.Parent.Time; local function string_ChooseMap () local x = {}; for a , _ in pairs(Maps) do table.insert(x, a); end local random = x[math.random(#x)]; return random; end local function void_Intermission () for i = 30, 1, -1 do Time.Text = t; print("Time " .. i); wait(1); end local map = array_ChooseMap(); for _, plr in pairs(game.Players:GetPlayers()) do plr.Character.HumanoidRootPart.CFrame = Maps[map]; end end script.Parent.StartRound.MouseButton1Click:Connect(void_Intermission);