Hello, everyone.
I’m making a top-down view game, and I need to make so the camera doesn’t see stuff it it isn’t supposed to, and by “stuff” I mainly mean the slightly transparent gray blocks in the photo below.
Basically, I need to player to see the map boundaries as camera boundaries. something like this:
I have searched for possible solutions, but no matter what I do it doesn’t as I want it to work.
Here’s the camera code I currently have:
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local player = players.LocalPlayer
local camera = workspace.CurrentCamera
local cameraX
local cameraY
local cameraZ
local cameraPosition
local cameraBoundaries = false
task.wait(3)
repeat
script:SetAttribute("PlayerToFollow", player.Character.Name)
until player.Character
local function updateCamera()
local character = workspace:FindFirstChild(script:GetAttribute("PlayerToFollow"))
if character then
local root = character:FindFirstChild("HumanoidRootPart")
if root then
local rootPosition = root.Position + Vector3.new(0, script:GetAttribute("CameraHeight"), 6) -- CameraHeight must be 40
if rootPosition.X > 31.5 then
print("X Over 31.5")
cameraX = 31.5
elseif rootPosition.X < -31.9 then
print("X less that -31.9")
cameraX = -31.9
else
print("X")
cameraX = rootPosition.X
end
if rootPosition.Z > 53.72 then
cameraZ = 53.72
elseif rootPosition.Z < -65 then
cameraZ = -65
else
print("Z")
cameraZ = rootPosition.Z
end
print(cameraX, cameraZ)
if cameraBoundaries == true then
cameraPosition = Vector3.new(cameraX, rootPosition.Y, cameraZ - 1)
else
cameraPosition = Vector3.new(rootPosition.X, rootPosition.Y, rootPosition.Z - 1)
end
--camera.CFrame = CFrame.new(rootPosition, root.Position)
camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition + Vector3.new(0, -90, 0))
end
end
end
runService:BindToRenderStep("90DegreesCamera", Enum.RenderPriority.Camera.Value + 1, updateCamera)
Tell me if you need some additional information or something else entirely.
Thanks for reading!
And helping!
if you do


