Manipulating string to object. Is this possible?
What i try to do is manipulating an string to a object location.
1 | local level = game.Workspace [ "Shop-Leaderboard" ] .lvl.Value |
2 | local map = ( "Map" .. level) |
3 | local current_level = ( "game." .. map) |
4 | local current_camera = (current_level .. ".cam" ) |
This part of the script returns the following.
Those elements are present in my tree. This is correct.
Now I want to use this brick to set my camera positiosn
01 | local function onRenderStep() |
02 | local character = player.Character |
04 | local humanoidRootPart = game.Workspace.Map [ level ] .cam |
05 | if humanoidRootPart then |
06 | local playerPosition = humanoidRootPart.Position |
07 | local cameraPosition = playerPosition + OFFSET |
08 | camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition) |
But obvious this does not work. Cause I use a string instead of an object.
How can i change this string "current_level" or "game.Workspace.Map[level].cam" to an object type?
Here is the whole script:
01 | local RunService = game:GetService( "RunService" ) |
02 | local Players = game:GetService( "Players" ) |
04 | local OFFSET = Vector 3. new( 40 , 40 , 40 ) |
05 | local FIELD_OF_VIEW = 40 |
07 | local player = Players.LocalPlayer |
08 | local camera = game.Workspace.CurrentCamera |
10 | camera.FieldOfView = FIELD_OF_VIEW |
12 | local level = game.Workspace [ "Shop-Leaderboard" ] .lvl.Value |
13 | local map = ( "Map" .. level) |
14 | local current_level = ( "game." .. map) |
15 | local current_camera = (current_level .. ".cam" ) |
20 | local function onRenderStep() |
21 | local character = player.Character |
23 | local humanoidRootPart = game.Workspace.Map [ level ] .cam |
24 | if humanoidRootPart then |
25 | local playerPosition = humanoidRootPart.Position |
26 | local cameraPosition = playerPosition + OFFSET |
27 | camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition) |
32 | RunService:BindToRenderStep( "Camera" , Enum.RenderPriority.Camera.Value, onRenderStep) |