Why doesnt my realistic first person script mode doesn't work

game.Players.LocalPlayer.CharacterAdded:Connect(function(z)
	for i,v in pairs(z:GetChildren()) do

		if v.Name ~= "Head" and v:IsA("BasePart")or v:IsA("MeshPart")then
			
			   v.LocalTransparencyModifier= 0
			if v.LocalTransparencyModifier == 0 then
				print("Success")
			end
			
		end
	end
end)
	

this is my script also didn’t print “Success”
-A localScript in the StarterCharacterScripts

The issue might be because the character loaded before .CharacterAdded event loaded, meaning it wouldn’t load. Try checking if the player already exists.

local Player = game.Players.LocalPlayer

if Player.Character then
-- code here
end
1 Like

I think i did something wrong here

local Player = game.Players.LocalPlayer

if Player.Character then
	Player.CharacterAdded:Connect(function(a)
		for i,v in pairs(a:GetChildren()) do

			if  v.Name ~= "Head" and v:IsA("BasePart")or v:IsA("MeshPart")then

				v.LocalTransparencyModifier= 0
				if v.LocalTransparencyModifier == 0 then
					print("Sucess")
				end
			end
		end
	end)
end
	

Wait, try this script instead. I would recommend checking for these three things when changing the character part’s LocalTransparencyModifier:

  1. If the player has already loaded
  2. The CharacterAdded event, just incase the player hasn’t loaded
  3. If something gets added to the player
local Player = game.Players.LocalPlayer

local function FirstPerson(a)
	for i,v in pairs(a:GetChildren()) do
		if v.Name ~= "Head" and v:IsA("BasePart") or v:IsA("MeshPart") then
			v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
				v.LocalTransparencyModifier = 0
				
				if v.LocalTransparencyModifier == 0 then
					print("Sucess")
				end
			end)
		end
	end
end

Player.CharacterAdded:Connect(function(a)
	FirstPerson(a)
end)

if Player.Character then
	FirstPerson(Player.Character)
	
	Player.Character.ChildAdded:Connect(function()
		FirstPerson(Player.Character)
	end)
end
1 Like

Awesome it worked and Thanks for those points it helped alot

1 Like

You’re welcome! Good luck on your project :wink:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.