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

Manipulating string to object. Is this possible?

Asked by
ik951m 0
7 years ago

What i try to do is manipulating an string to a object location.

1local level = game.Workspace["Shop-Leaderboard"].lvl.Value
2local map = ("Map" .. level)
3local current_level = ("game." .. map)
4local current_camera = (current_level .. ".cam")
5print(current_level)
6print(current_camera)

This part of the script returns the following.

1game.Map0
2game.Map0.cam

Those elements are present in my tree. This is correct. Now I want to use this brick to set my camera positiosn

01local function onRenderStep()
02    local character = player.Character
03    if character then
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)
09        end
10    end

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:

01local RunService = game:GetService("RunService")
02local Players = game:GetService("Players")
03 
04local OFFSET = Vector3.new(40,40,40)
05local FIELD_OF_VIEW = 40
06 
07local player = Players.LocalPlayer
08local camera = game.Workspace.CurrentCamera
09 
10camera.FieldOfView = FIELD_OF_VIEW
11 
12local level = game.Workspace["Shop-Leaderboard"].lvl.Value
13local map = ("Map" .. level)
14local current_level = ("game." .. map)
15local current_camera = (current_level .. ".cam")
View all 32 lines...

1 answer

Log in to vote
1
Answered by 7 years ago
1workspace["Map" .. level]

boom

0
concatenation for tha win Goulstem 8144 — 7y
0
Nice :) Thanks! ik951m 0 — 7y
1
If it worked, accept his answer :l awfulszn 394 — 7y
Ad

Answer this question