✓ 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 =
game.Workspace.Value.Changed:Connect(function()
if game.Workspace.Value.Value == true then
for i,v in pairs() do
if v.Character then
if v.Character:FindFirstChild("Torso") then
v.Character.Torso.CFrame = spawnParts["SP-"..math.random(1,10)]
end
end
end
end
end)
Any questions? Put down a comment :)
2 comments
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
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.