Is this gonna be laggy since it uses viewport frame, and copies the whole workspace 3 times
local rep = game:GetService'ReplicatedStorage'
local tween = game:GetService'TweenService'
local wait = task.wait
local flashbangEvent = rep:WaitForChild'Flashbang'.OnClientEvent
local viewport = script.Parent:WaitForChild'Viewport'
local whiteFrame = script.Parent:WaitForChild'Frame'
local cam = Instance.new("Camera",script.Parent)
local tweens:{Tween} = {
tween:Create(whiteFrame,TweenInfo.new(6,Enum.EasingStyle.Linear),{BackgroundTransparency = 1}),
tween:Create(viewport,TweenInfo.new(.7,Enum.EasingStyle.Linear),{ImageTransparency = 1}),
tween:Create(viewport,TweenInfo.new(.3,Enum.EasingStyle.Linear),{BackgroundTransparency = 1}),
}
viewport.CurrentCamera = cam
local function setFrame()
cam.CFrame = workspace.Camera.CFrame
for _, v in pairs(workspace:GetChildren()) do
if v:IsA'Camera' or v:IsA'Terrain' then continue end
local clone = v:Clone()
if clone then clone.Parent = viewport end
end
viewport.ImageTransparency = .3+whiteFrame.BackgroundTransparency
viewport.BackgroundTransparency = 2*whiteFrame.BackgroundTransparency
wait(.3)
tweens[2]:Play()
tweens[3]:Play()
end
flashbangEvent:Connect(function()
whiteFrame.BackgroundTransparency = 0
tweens[1]:Play()
wait(1)
for i = 1, 3 do
wait(1)
setFrame() -- I just turned it into a function so it looks a bit more clean
end
tweens[2].Completed:Wait()
viewport:ClearAllChildren()
end)
im setting the cframe of the viewport camera to the cframe of the client camera, then copy the whole workspace so its like getting the current frame of the player. 3 times cuz it “copies” the frame 3 times
Ok got it, it’s pretty memory expensive on client to clone the map 3 times, you could also clone the map at server join and clone moving objects like players when doing the flash.
I was actually searching if there was a way to get the current frame in roblox, but there was none so i thought what if get all visible parts in the current frame, I found nothing. there could be a way though, I just cant find it
you could use raycasts to get all the visible parts in a frame, but I assume that will also be very laggy. The lag might be able to be reduced by lowering the amount of raycasts though, but at the expense of the raycasts missing some parts
ive thought of using raycast but i realized that its expensive, especially when looking at far distances. Reducing the amount of raycast will miss most parts in a model, it is only good when only rendering flat walls. Shrinking the raycast range is also an option but is bad for large open field maps.
Im still sticking to copying only the moving parts and stationary parts are only copied once
I think attach a sphere in front of the player that the edge of the sphere is right on their face,Move it with the movement of camera,Clone everything inside the sphere into the viewport frame.If you change the size of the spehere it will change the copying distance.This roughly imitate FOV of the player
ps.The speher should be attach to the camera instead