Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Vain_p 78
5 years ago
Edited 5 years ago

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);
0
please fix your lua tags, enclose your code within those tildes GoldAngelInDisguise 297 — 5y
0
Please put your code inside the lua tags. TypicallyPacific 61 — 5y
0
Please fix your qeustion, place the code inside the lua code block tags. SteamG00B 1633 — 5y
0
I answered your question, if it helps you, then please accept it as the correct answer SteamG00B 1633 — 5y
View all comments (4 more)
0
Also edit your title because it has nothing to do with what your question really is SteamG00B 1633 — 5y
0
So does it work? I'd like to know if you need anymore help SteamG00B 1633 — 5y
0
If my answer solves your problem, then mark it as the accepted answer SteamG00B 1633 — 5y
0
Should be a button the the upper right hand side of my answer that says something about accepting the answer SteamG00B 1633 — 5y

2 answers

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
lol I forgot about the Character thank you so much will try! Vain_p 78 — 5y
0
and the if statement is for when I add more maps Vain_p 78 — 5y
0
If this works, then please mark it as the accepted answer SteamG00B 1633 — 5y
0
ah makes sense :) SteamG00B 1633 — 5y
View all comments (12 more)
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 SteamG00B 1633 — 5y
0
He ran off dude. Zafirua 1348 — 5y
0
Well since you said I copied yours, I went ahead and made it even better :) AbstractionsReality 98 — 5y
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. SteamG00B 1633 — 5y
0
Do you even know what his original question was? AbstractionsReality 98 — 5y
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. AbstractionsReality 98 — 5y
0
can you guys not argure I was eating pizza and I can't find the accept buttom Vain_p 78 — 5y
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 SteamG00B 1633 — 5y
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. Zafirua 1348 — 5y
0
https://gyazo.com/952d788a0cb2d566a80f3482cce0d666 I really don't see what your problem is.  Zafirua 1348 — 5y
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. SteamG00B 1633 — 5y
0
Well AbstractionsReality is actually me....Thanks for the concern however.  Zafirua 1348 — 5y
Ad
Log in to vote
3
Answered by 5 years ago
Edited 5 years ago

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);
0
ok I will try that thanks Vain_p 78 — 5y
0
Also it Errors at line 13 Vain_p 78 — 5y
0
Try now. I reverted back to your old way. Be sure to accept the answer! AbstractionsReality 98 — 5y
0
Errors at same place Line 12 I am trying to tp all players to that place Vain_p 78 — 5y
View all comments (9 more)
0
lua is actually one of the languages that doesn't require semicolons to terminate lines, you can leave it open SteamG00B 1633 — 5y
0
also, why is your code exactly like the one in his question? SteamG00B 1633 — 5y
0
^ He updated from my code. AbstractionsReality 98 — 5y
0
He shouldn't have done that, and anyway, it is still wrong SteamG00B 1633 — 5y
0
I still need help with line 12 :/ Vain_p 78 — 5y
0
you can't have player defined twice like that, it will cause problems, plus that line is still wrong besides that SteamG00B 1633 — 5y
0
How else is it wrong? AbstractionsReality 98 — 5y
0
well now it's right, except that's because you copied my answer and changed the variables SteamG00B 1633 — 5y
0
This isn't a request site, by writing code for someone's request, you are encouraging people to make requests. SteamG00B 1633 — 5y

Answer this question