Hello!
I got a problem with this script, fps drops when equipping tool
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
game:GetService("RunService").RenderStepped:Connect(function()
for _, i in pairs(Character:GetChildren()) do
if string.match(i.Name, "Arm") or string.match(i.Name, "Leg") then
i.LocalTransparencyModifier = 0
end
end
end)
Any ideas how to fix this? Or is there another method to make arms visible in first person?
1 Like
local RunService = game:GetService("RunService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
-- instead of scanning every frame for the right part,
-- scan once when the script starts!
local PartsVisibleInFirstPerson = {}
local function FindPartsVisibleInFirstPerson()
-- moved your loop and made some changes
for _, Limb in Character:GetChildren() do
if Limb.Name:match("Arm") or Limb.Name:match("Leg") then
table.insert(PartsVisibleInFirstPerson, Limb)
end
end
end
FindPartsVisibleInFirstPerson()
-- also tweaked the way you were connecting to "RenderStepped",
-- i believe this is just the same signal with a clearer name
RunService.PreRender:Connect(function()
-- now, instead of scanning every frame, just edit the limbs you know.
for _, Part in PartsVisibleInFirstPerson do
Part.LocalTransparencyModifier = 0
end
end)
2 Likes
You saved my nerves, thank you very much!
Edit: not a solution, didn’t fully check
Just wanted to doublecheck with you, did this actually entirely solve the frame drop issue? Obviously using more efficient code that runs every frame will boost your performance however I just realised that the arms and legs are still visible even when the tool isn’t equipped yet in the video, meaning this script still runs even while the tool isn’t equipped; maybe its a different script that only activates when the tool is equipped that is the one causing you trouble?
You can try the “MicroProfiler” tool to doublecheck how every frame is being processed and find where the biggest chunk of time is being wasted, and where.
Oh, I was in a hurry, the FPS is ok for the first couple of seconds and then it drops again, sorry for that
1 Like
I also noticed that the problem is definitely not in the tool model, I tried different models and still FPS dropped
As for the script in the tool, I tested in an empty place, with this one script and a tool without scripts
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
game:GetService("RunService").RenderStepped:Connect(function()
for _, i in pairs(Character:GetChildren()) do
if string.match(i.Name, "Arm") or string.match(i.Name, "Leg") then
i.LocalTransparencyModifier = 0
end
end
end)
Found solution, i modifed TransparencyController
Line 219 to:
if not string.match(child.Name, "Arm") and not string.match(child.Name, "Leg") and not string.match(child.Name, "Torso") then
child.LocalTransparencyModifier = transparency
end
It’s just works
1 Like