Something is making my character transparent

Hi guys, I am working on a weapon engine


But… this happens when switching from first to third person no clue why :confused:

This is the code;

function guns:SwitchCameraType()
	local x = self.CameraType
	self.CameraType = x ~= 'TPS' and 'TPS' or 'FPS'
	x = self.CameraType
	if (x == 'FPS') then
		self.CameraSystem:Disable()
		self.Player.CameraMaxZoomDistance = 0.5
		workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	else
		self.Player.CameraMaxZoomDistance = 128
		workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		self.CameraSystem:Enable()
	end
end

“CameraSystem”
Is the OTS camera system by @Arbeiters

1 Like

Check to see if the OTS is changing any transparency values.

If not, then it’s probably something done automatically by the Roblox Camera System, like how you don’t see your own character when going in first person.

I’d say manually set the transparency back to 0 when zooming out for the latter, so you don’t have to edit core scripts.

Nope, OTS seems like no,
But looks like the Roblox core takes like the camera were close to the body, so it makes it transparent :thinking:

This happens because the camera type is changed to scriptable before zooming out. The transparency controller becomes disabled before it can reset the character’s transparency. https://www.youtube.com/watch?v=FzCYQl5th5s
I’m not really familiar with the transparency controller however, you can reset the transparency by requiring the transparency controller, calling its .new() function, then call :SetupTransparency(Character), then running :Update()
Take this code as an example

-- This local script resets the player's transparency whenever the 'R' key it pressed.
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local TransparencyModule = require(player.PlayerScripts:WaitForChild("PlayerModule").CameraModule.TransparencyController)
local controller = TransparencyModule.new()
controller:SetupTransparency(character)

function resetTransparency()
	controller:Update() -- Resets the transparency
	controller["transparencyDirty"] = true -- "transparencyDirty" get's set to false and when it's false the controller will not reset the transparency.
end

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.R and not gameProcessedEvent then
		resetTransparency()
	end
end)

Just be sure to set transparencyDirty to false before calling :Update() or the transparency will not be reset

Hi, there’s a trouble, all the character parts are non transparent, so it looks bad now :confused:

Try resetting the player’s transparency only when they exit first person, that should fix your problem.
I don’t know your code for toggling the first person mode so I can’t go into much detail.

Still the same.
For toggling the first person I am just locking the cameramode of player to Enum.CameraMode.LockFirstPerson.
And for third person I am locking in ‘CLassic’ and changing Player.CameraMinZoomDistance = 3

I’ve made this;
define it

function guns.equip(GunModel,Arm)
( removed the other variables :D)
	self.controller = TransparencyModule.new()
	self.controller:SetupTransparency(self.Character)
self:Equip()
	return setmetatable(self,guns)
end

Switching from first/third;

function guns:SwitchCameraType()
	local x = self.CameraType
	self.CameraType = x ~= 'TPS' and 'TPS' or 'FPS'
	x = self.CameraType
	if (x == 'FPS') then
		self.CameraSystem:Disable()
		self.Player.CameraMode = Enum.CameraMode.LockFirstPerson
		self.Player.CameraMinZoomDistance = 0.5
		workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	else
		self.UIS.MouseIconEnabled = true
		self.Player.CameraMode = Enum.CameraMode.Classic
		self.Player.CameraMinZoomDistance = 3
		self.CameraSystem:Enable()
		self.controller:Update()
	end
end

Can someone help? :confused:
Don’t really know how to fix it

So after playing around with the transparency controller I can finally say that I’ve found a better way to change that players transparency that allows you to set it to whatever value you want it to be!
Instead of calling :Update() we can instead get each of it’s .cachedParts and change their .LocalTransparencyModifier value to whatever transparency we want.
Here’s my updated code

-- This local script toggles the player's transparency every second.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local TransparencyModule = require(player.PlayerScripts:WaitForChild("PlayerModule").CameraModule.TransparencyController)
local controller = TransparencyModule.new()
controller:SetupTransparency(character)

function becomeTransparent()
	for i, _ in pairs(controller.cachedParts) do
		i.LocalTransparencyModifier = 1
	end
end
function resetTransparency()
	for i, _ in pairs(controller.cachedParts) do
		i.LocalTransparencyModifier = 0
	end
end

while wait(1) do
	becomeTransparent()
	wait(1)
	resetTransparency()
end
3 Likes

Thanks so much!!
Look how the gun kit is looking :smiley:

1 Like