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)

3 comments
concatenation for tha win
Nice :) Thanks!
If it worked, accept his answer :l