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

Player arms are no longer visible in first person after dying. Can someone help?

Asked by 3 years ago

I made a tool which your arms become visible in first person when you equip and disappear when you unequip the tool in a local script in the tool. However, after you die, it just does not work. I've tried a few things, but it never seemed to work. If someone could help I'd appreciate it a bunch !!



local self,player = script.Parent,game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:wait() local humanoid = char:WaitForChild("Humanoid") -- waits for the humanoid in the character function antiTrans(part) if part and part:IsA("BasePart") and( part.Name=="Right Arm") then -- checks if a part and is a arm part.LocalTransparencyModifier = 0 end end function Trans(part) if part and part:IsA("BasePart") and( part.Name=="Right Arm") then -- checks if a part and is a arm part.LocalTransparencyModifier = 1 end end script.Parent.Equipped:Connect(function() for _,v in pairs(char:GetChildren()) do antiTrans(v) -- adds all parts end end) script.Parent.Unequipped:Connect(function() for _,v in pairs(char:GetChildren()) do Trans(v) -- adds all parts end end)

fyi, the code came from the dev forum, i just edited the code a little bit to make it work until i came across the error

0
If you need help understanding the question, let me know! jorcorrs 76 — 3y

1 answer

Log in to vote
1
Answered by
Rinpix 639 Moderation Voter
3 years ago
Edited 3 years ago

You should be doing this entirely differently.

local tool,player = script.Parent,game.Players.LocalPlayer
local char
repeat
    wait()
    char = player.Character
until char
local humanoid = char:WaitForChild("Humanoid") -- waits for the humanoid in the character

tool.Equipped:Connect(function()
    for _, part in pairs(char:GetChildren()) do
        if (part:IsA("BasePart") and (string.find(part.Name, "Arm") or string.find(part.Name, "Hand"))) then
            spawn(function()
                while (tool.Parent == char) do
                    wait()
                    part.LocalTransparencyModifier = 0
                end
                local zoomDistance = (game.Workspace.CurrentCamera.CFrame.Position - char.Head.Position).Magnitude
                if (zoomDistance <= 1) then
                    part.LocalTransparencyModifier = 1
                end
            end)
        end
    end
end)

You can see that I've changed how the "char" variable is assigned. It looks terribly inefficient, but it's a workaround to what seems to be a weird bug that prevents your code from working properly if you do "char = player.Character or player.CharacterAdded:Wait()". I've had this issue in the past and I don't know what it is, but it seems to be a bug on Roblox's part.

Whenever you equip the tool, you need to repeatedly set the LocalTransparencyModifier of all of the arm parts to 0, because if you just set it once, it'll be overridden by the scripts that set it as you zoom in or out. Whenever you unequip it, you will need to measure the zoom distance, which is just the distance between the Camera's position and your head's position, to determine whether or not the player is in first person. If the distance is less than a stud then they're probably in first person. If you don't check the zoom distance and just set the LocalTransparencyModifier to 1 their arms will be invisible, even in third person, which is why you need to check the zoom distance, assuming this game allows for first and third person.

I also saw that you used "self" as the name of a variable, and while the script would still work, it's not a good idea, because "self" is a keyword in Lua, and you shouldn't use keywords as the names of variables, so I just used "tool" instead.

You were also using two functions to do what could be done with one. Just set up a parameter that allows you to pass in a value which you could set the transparency of the part to.

Ad

Answer this question