Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

LocalTransparencyModifier not working as expected?

Asked by 4 years ago

Hello, in my game, I have the character's arms visible in first person, but I find it that when scoped in with a sniper rifle, the arms remain in the way, obstructing view. Here's my code for it;

local player = game.Players.LocalPlayer;
local rs = game:GetService("RunService");

local character = player.Character
local camera = game.Workspace.CurrentCamera


rs.RenderStepped:Connect(function()
    if not player.Character:FindFirstChild("Sniper Rifle") then --if they have any other weapon out...
        character["Right Arm"].LocalTransparencyModifier = 0
        character["Left Arm"].LocalTransparencyModifier = 0
    else --If they do have a sniper equipped...
        character["Right Arm"].LocalTransparencyModifier = 1
        character["Left Arm"].LocalTransparencyModifier = 1
    end

end)

I don't fully understand LocalTransparencyModifier, so any and all help on it would be greatly appreciated!

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Ok, so you said you want a walkthrough. According to this developer.roblox.com post,

The LocalTransparencyModifier property is a multiplier to BasePart.Transparency that is only visible to the local client. It does not replicate from client to server. It is useful for when a part should not render for a specific client, such as how the player does not see their character’s body parts when they zoom into first person mode.

This is similar to your problem, here is a code sample that I have added notes to, to better help you understand:

local player = game.Players.LocalPlayer; --make sure you run game.Players.LocalPlayer in a LocalScript, otherwise it won't work.
local rs = game:GetService("RunService");
local character = player.Character
local camera = workspace.CurrentCamera --changed from game.Workspace to workspace
local leftArm, rightArm; -- define these ahead of time

rs.RenderStepped:Connect(function()
    if not character:FindFirstChild("Sniper Rifle") then --if sniper isn't equipped
        leftArm.LocalTransparencyModifier = 0; --sets the left arm to 0 transparency
        rightArm.LocalTransparencyModifier = 0; --sets the right arm to 0 transparency
    elseif character:FindFirstChild("Sniper Rifle") then --if sniper is equipped
        leftArm.LocalTransparencyModifier = 1; --sets the left arm to 1 transparency
        rightArm.LocalTransparencyModifier = 1; --sets the right arm to 1 transparency
    end;
end);

Not sure if this works, made it up in my head.

0
I'd love a walkthrough. Utter_Incompetence 856 — 4y
1
Going to edit my answer, stay tuned here. matiss112233 258 — 4y
0
Works! Utter_Incompetence 856 — 4y
Ad

Answer this question