Table script not working

Hello,
I’ve been trying to make a script that will math.random() from a table and change a patch.
Here is the script.

local table1 = {"CameraPart1", "CameraPart2", "CameraPart3"}
game.Workspace.CurrentCamera.CFrame = workspace.table1[math.random(1,#table1)].CFrame

For some reason the script does not work. Once i join the game, nothing happens, and the current camera has been not changed.

local table1 = {"CameraPart1", "CameraPart2", "CameraPart3"}
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable 
game.Workspace.CurrentCamera.CFrame = workspace.table1[math.random(1,#table1)].CFrame

Try this:

local table1 = {"CameraPart1", "CameraPart2", "CameraPart3"}
game.Workspace.CurrentCamera.CFrame = workspace[table1[math.random(1,#table1)]].CFrame
1 Like

by combining @CZXPEK solution and @domboss37 it might work

edit: wrong reply

It does not work for some reason. Here is the full script

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = game.Workspace.CurrentCamera
local table1 = {"CameraPart1", "CameraPart2", "CameraPart3"}

local PlayButton = script.Parent.PlayButton

repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace[table1[math.random(1,#table1)]].CFrame

try using a empty baseplate soooo

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = game.Workspace.CurrentCamera
local table1 = {"CameraPart1", "CameraPart2", "CameraPart3"}

local PlayButton = script.Parent.PlayButton

Camera.CameraType = Enum.CameraType.Scriptable

Camera.CFrame = workspace[table1[math.random(1,#table1)]].CFrame

That might work, I don’t see the reason for the repeat wait until Loop, however, make sure your script is a local script

Yes i am using a local script, however the script still doesn’t work. Also there is nothing in the output.
When i try without match random, it seems to work

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = game.Workspace.CurrentCamera
local table1 = {"CameraPart1", "CameraPart2", "CameraPart3"}

repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart1.CFrame -- when i try without match random, it works

i think i know the problem i think its because its tring to find (workspace.table1.2.CFrame) so i think it dosent work

Interesting, maybe put it in a variable before you set the CFrame, so:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = game.Workspace.CurrentCamera
local table1 = {"CameraPart1", "CameraPart2", "CameraPart3"}

repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable

local CamPart = table1[math.random(1, #table1)]
Camera.CFrame = workspace[CamPart].CFrame
1 Like

This topic is already solved, thanks.