Hello, I asked this earlier, and I do need a bit more help
local SP1 = game.Workspace.SpawnPs["SP-1"] local SP2 = game.Workspace.SpawnPs["SP-2"] local SP3 = game.Workspace.SpawnPs["SP-3"] local SP4 = game.Workspace.SpawnPs["SP-4"] local SP5 = game.Workspace.SpawnPs["SP-5"] local SP6 = game.Workspace.SpawnPs["SP-6"] local SP7 = game.Workspace.SpawnPs["SP-7"] local SP8 = game.Workspace.SpawnPs["SP-8"] local SP9 = game.Workspace.SpawnPs["SP-9"] local SP10 = game.Workspace.SpawnPs["SP-10"] local players = game.Players local spawnParts = SP1,SP2,SP4,SP5,SP6,SP7,SP8,SP9,SP10 game.Workspace.GameStats.GameRunning.Changed:Connect(function() -- you said fire on workspace value changed. if game.Workspace.Value.Value == true then for i,v in pairs(game.Players:GetPlayers()) 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)
For some reason, its not bringing players to the parts. Any help appreciated!
For one, you don't need to define all of those spawn positions. You can simply just call GetChildren
on SpawnPs
, which will return an array of all the instances that you can just randomly index.
Your actual problem is you're trying to assign a tuple to spawnParts
with a single variable, which is a logical fallacy (a single variable can't have more than one reference at the same time). You probably meant to put that tuple inside of a table, which is still redundant since like I said before, you can just use GetChildren
. Here, try this:
local players = game:GetService("Players") local spawnParts = workspace:WaitForChild("SpawnPs") local spawns = spawnParts:GetChildren() ValueObject.Changed:Connect(function() if (Condition) then for _, player in next, players:GetPlayers() do local torso = player.Character and player.Character:FindFirstChild("Torso") if torso then -- Get a random number between 1-#spawns, and return the object in that index. This is the standard method of returning pseudo-random data from an array. local randomCF = spawns[math.random(#spawns)].CFrame torso.CFrame = randomCF end end end end)
If you have any questions, just let me know.
Since i answered your previous answer, i should fix my own mistake(s) XD
--line 1-10, 13 spawnParts = game.Workspace.SpawnPs:GetChildren() --line 16 --Probably change that to if game.Workspace.GameStats.GameRunning.Value == true then --line 20 v.Character.Torso.CFrame = spawnParts["SP-"..math.random(1,#spawnParts)].CFrame + Vector3.new(0,5,0)