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

Why isnt CFrame working properly?

Asked by 7 years ago

I am trying to pick a random CFrame from a table so the players can teleport to a random CFrame...

local Ceev= {CFrame.new(-6601.1, 216.5, 137.8),CFrame.new(-6685.1, 216.5, 187.2)}
local Ctarget = math.random(#Ceev)
print(Ctarget)
for i, player in pairs(game.Players:GetPlayers()) do
 player.Character.Torso.CFrame = Ctarget + Vector3.new( 0 * math.random(1, 2) , 0 * 2 , i * 2)
end

1 answer

Log in to vote
2
Answered by 7 years ago

You haven't set Ctarget to one of the values in Ceev, you've set it to a random number up to the number of values in Ceev. You need to do Ceev[math.random(1,#Ceev)] to do this correctly.

local Ceev= {CFrame.new(-6601.1, 216.5, 137.8),CFrame.new(-6685.1, 216.5, 187.2)}
local Ctarget = Ceev[math.random(1,#Ceev)]
print(Ctarget)
for i, player in pairs(game.Players:GetPlayers()) do
    player.Character.Torso.CFrame = Ctarget + Vector3.new( 0 * math.random(1, 2) , 0 * 2 , i * 2)
end

Hope this works for you!

Ad

Answer this question