Hello! I am working on the viewmodel which is made to be played in first and third person view.
Whether I’m zooming, either first or third person view, it should be able to update viewmodel transparency immediately because I made it so it can update on every frame.
For some reason, I encounter an annoying problem in which when I zoom in first-person view, it works fine because the transparency immediately updates. But when I zoom out in third-person, it delays for a moment before making the viewmodel invisible.
I’m not sure if it’s me or the Roblox Studio bug itself. But I’ve been doing this for hours trying to fix this, but it’s no use. Mine is running very smoothly, around 60 FPS, no lag. Any help would be awesome!
Here’s the code, it’s a long code but I shorten them so it’ll be easier to understand what I’m focusing on.
Hope I don’t confuse your mind. Everything is working fine, it’s the only delaying part that’s bothering me.
Weapon Settings
local Settings = {
acceptableclasses = {"Part", "MeshPart", "UnionOperation"}
}
return Settings
LocalScript
local WeaponSettings = require(script.Parent:WaitForChild("Settings"))
local RS= game:GetService("RunService")
RS.RenderStepped:connect(function()
local firsttable = {} --table for viewmodel, first person view
local thirdtable = {} --talbe for tool player is holding, third person view
for _, f in pairs(camera.FirstPersonBody:GetDescendants()) do --Find parts in viewmodel (first person view, then insert it into "firsttable.")
for _, ac in pairs(WeaponSettings.acceptableclasses) do
if f:IsA(ac) then
table.insert(firsttable, f)
end
end
end
for _, t in pairs(script.Parent:GetDescendants()) do --Find parts from gun the player is holding (third person view, then insert it into "thirdtable.")
for _, ac in pairs(WeaponSettings.acceptableclasses) do
if t:IsA(ac) then
table.insert(thirdtable, t)
end
end
end
if CameraDistance > 0.6 then --Distance between camera position and player's head
--Third Person View
for _, f in pairs(firsttable) do
f.Transparency = 1
end
for _, t in pairs(thirdtable) do
t.Transparency = 0
end
else
--First Person View
for _, f in pairs(firsttable) do
f.Transparency = 0
end
for _, t in pairs(thirdtable) do
t.Transparency = 1
end
end
end)