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

I,v in pairs to get cframe torso to baseplate help?

Asked by 8 years ago
Edited 8 years ago

Lol, confusing name I know.

So, me and iv in pairs aren't good friends, and I'm just learning to script, but I require some assistance. Basically, im making a round based game, and i dont know how to get it to move all players randomly to bricks names SP-1, SP-2, and so on to SP-10, when I set a value in workspace to true. Would anyone mind helping me out?

0
You don't have to refer to it as "iv pairs". The "i" and "v" are just variables, and "pairs" is just the iterator to your for loop. You can just call it a for loop, or more specifically, a *generic* for loop as explained here: https://www.lua.org/pil/4.3.5.html ScriptGuider 5640 — 8y
0
Also, could you provide samples of your code highlighting the problem? You should also provide any error messages the output window gives you, or if there aren't any. ScriptGuider 5640 — 8y

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
8 years ago
Edited 8 years ago

I'm going to explain something about i,v.

a "iv" for loop, loops though all things given in in pairs(-here-)

i,v can be any value. Mostly we don't use the i value, so we put in for _,v in but that doesn't make a difference either. (Just for decorations)

If we say for i,v in pairs(game.Workspace:GetChildren()) do it would loop through each child of the workspace.

i is the number of loops that have passed. v is the instance that is currently picked out of the pairs(-here-)

For players, this would be pairs(game.Players:GetPlayers())

Now for the script.

As this isn't a request site im going to leave a few blanks for you to fill in.

I'd suppose all these "SP-#" parts are in all in a model.

local players = game.Players
local spawnParts = --fill

game.Workspace.Value.Changed:Connect(function() -- you said fire on workspace value changed.
    if game.Workspace.Value.Value == true then
        for i,v in pairs(--[[fill]]) do -- Loop through all players
            if v.Character then
                if v.Character:FindFirstChild("Torso") then
                    v.Character.Torso.CFrame = spawnParts["SP-"..math.random(1,10)] -- Set the torso's cframe to spParts.SP-(1 to 10)
                end
            end
        end
    end
end)

Any questions? Put down a comment :)

0
Hey thanks man! Just wondering, after you say the .. then math.random, is the ".." for adding into the name? QuantumWaffle 17 — 8y
0
Yeah .. is concatination. You can wiki it ;) RubenKan 3615 — 8y
0
Also, if this brought you to a solution of your problem, Don't forget to hit the *accept answer* button :) RubenKan 3615 — 8y
0
Also, for the in pairs(--[[fill]]) what exactly would I put? QuantumWaffle 17 — 8y
View all comments (2 more)
0
You can seen that if you read everything. *For players, this would be pairs(game.Players:GetPlayers())* RubenKan 3615 — 8y
0
Ah, i did read everything, i apologize. QuantumWaffle 17 — 8y
Ad

Answer this question