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
6 years ago

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

local level = game.Workspace["Shop-Leaderboard"].lvl.Value
local map = ("Map" .. level)
local current_level = ("game." .. map)
local current_camera = (current_level .. ".cam")
print(current_level)
print(current_camera)

This part of the script returns the following.

game.Map0
game.Map0.cam

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

local function onRenderStep()
    local character = player.Character
    if character then
        local humanoidRootPart = game.Workspace.Map[level].cam
        if humanoidRootPart then
            local playerPosition = humanoidRootPart.Position
            local cameraPosition = playerPosition + OFFSET
            camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition)
        end
    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:

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local OFFSET = Vector3.new(40,40,40)
local FIELD_OF_VIEW = 40

local player = Players.LocalPlayer
local camera = game.Workspace.CurrentCamera

camera.FieldOfView = FIELD_OF_VIEW

local level = game.Workspace["Shop-Leaderboard"].lvl.Value
local map = ("Map" .. level)
local current_level = ("game." .. map)
local current_camera = (current_level .. ".cam")
print(current_level)
print(current_camera)


local function onRenderStep()
    local character = player.Character
    if character then
        local humanoidRootPart = game.Workspace.Map[level].cam --character:FindFirstChild("HumanoidRootPart")
        if humanoidRootPart then
            local playerPosition = humanoidRootPart.Position
            local cameraPosition = playerPosition + OFFSET
            camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition)
        end
    end
end

RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, onRenderStep)

1 answer

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

boom

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

Answer this question