Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Need help with minigame script Can't teleporting to work Any help? For time = 1,30

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);

8 comments

0

please fix your lua tags, enclose your code within those tildes

0

Please put your code inside the lua tags.

0

Please fix your qeustion, place the code inside the lua code block tags.

0

I answered your question, if it helps you, then please accept it as the correct answer

0

Also edit your title because it has nothing to do with what your question really is

0

So does it work? I'd like to know if you need anymore help

0

If my answer solves your problem, then mark it as the accepted answer

0

Should be a button the the upper right hand side of my answer that says something about accepting the answer

2 answers

✓ Accepted answer

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.

16 comments

0

lol I forgot about the Character thank you so much will try!

0

and the if statement is for when I add more maps

0

If this works, then please mark it as the accepted answer

0

ah makes sense :)

0

Is there something wrong with this? You've gone silent for a long time and I don't see anything wrong with this, so if there are any errors you are getting, let me know so I can fix them

0

He ran off dude.

0

Well since you said I copied yours, I went ahead and made it even better :)

0

That doesn't answer his question though, this isn't a request site, so by giving him code that he requested, you are violating the community guidelines.

0

Do you even know what his original question was?

0

I sure know that you don't. His original question was why the for loop was not executing. It was because he had messed up on the syntax. So technically, I already had solved the problem. And also there is nothing wrong with giving more informations than needed.

0

can you guys not argure I was eating pizza and I can't find the accept buttom

0

Actually there is something wrong with giving more information when the script is something he requested, recently I was told that on this site, if you merely do something relating to breaking a rule, then it is a violation of the entire rules

0

Since when is giving more information than needed a wrong thing. It is a problem when you provide little to no information but more information than needed will always help the person out. I mean, even the OP said in the chat that it did help him out.

0

https://gyazo.com/952d788a0cb2d566a80f3482cce0d666 I really don't see what your problem is. 

0

Yesterday people attacked me, told me I was encouraging the use of bad practices due to me not saying anything against the "bad practices", when there was no reason for me to say anything against the "bad practices". So I'd rather not let that happen to anyone else because these guys were just over the top.

0

Well AbstractionsReality is actually me....Thanks for the concern however. 

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);

13 comments

0

ok I will try that thanks

0

Also it Errors at line 13

0

Try now. I reverted back to your old way. Be sure to accept the answer!

0

Errors at same place Line 12 I am trying to tp all players to that place

0

lua is actually one of the languages that doesn't require semicolons to terminate lines, you can leave it open

0

also, why is your code exactly like the one in his question?

0

^ He updated from my code.

0

He shouldn't have done that, and anyway, it is still wrong

0

I still need help with line 12 :/

0

you can't have player defined twice like that, it will cause problems, plus that line is still wrong besides that

0

How else is it wrong?

0

well now it's right, except that's because you copied my answer and changed the variables

0

This isn't a request site, by writing code for someone's request, you are encouraging people to make requests.

This discussion is preserved as it was. New answers, comments, and votes are closed.