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

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

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?

2 comments

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

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.

1 answer

✓ Accepted answer

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

6 comments

0

Hey thanks man! Just wondering, after you say the .. then math.random, is the ".." for adding into the name?

0

Yeah .. is concatination. You can wiki it ;)

0

Also, if this brought you to a solution of your problem, Don't forget to hit the accept answer button :)

0

Also, for the in pairs(--[[fill]]) what exactly would I put?

0

You can seen that if you read everything. For players, this would be pairs(game.Players:GetPlayers())

0

Ah, i did read everything, i apologize.

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