I have a localscript in the playerscripts, which works fine when first loaded in, but breaks if the player dies and respawns, Its soooo anomalous (also maybe straight up obvious idk.)
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local MouseLocked = script:GetAttribute("MouseLock")
local Camera = workspace.CurrentCamera
local Client = game:GetService("Players").LocalPlayer
local Thread
local Sens = 0.2
Client.CameraMaxZoomDistance = 0
Client.CharacterAdded:Connect(function(NewCharacter)
local Character = NewCharacter
local Head = Character:WaitForChild("Head")
local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
local CameraDirection = Vector2.new(0, 0)
if Thread then
Thread:Disconnect()
Thread = nil
end
for _, Accessory in ipairs(Character:GetChildren()) do
if Accessory:IsA("Accessory") then
if Accessory.AccessoryType == Enum.AccessoryType.Hair or Accessory.AccessoryType == Enum.AccessoryType.Hat or Accessory.AccessoryType == Enum.AccessoryType.Face then
Accessory.Handle:AddTag("Ignore")
end
end
end
for _, Piece in ipairs(Character:GetDescendants()) do
if Piece:IsA("BasePart") and not Piece:HasTag("Ignore") and Piece.Name ~= "Head" then
Piece:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
Piece.LocalTransparencyModifier = Piece.Transparency
end)
Piece.LocalTransparencyModifier = Piece.Transparency
end
end
local function UpdateMouse(MouseLocked)
UserInputService.MouseIconEnabled = not MouseLocked
if MouseLocked == true then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
else
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end
Camera.CameraType = Enum.CameraType.Scriptable
end
Thread = RunService.RenderStepped:Connect(function()
UpdateMouse(script:GetAttribute("MouseLock"))
--if not Character then
-- return
--end
CameraDirection -= UserInputService:GetMouseDelta() * Sens
CameraDirection = Vector2.new(CameraDirection.X % 360, math.clamp(CameraDirection.Y, -85, 85))
Camera.CFrame = CFrame.new(Head.Position) * CFrame.new(0, 0.4, 0) * CFrame.fromOrientation(math.rad(CameraDirection.Y), math.rad(CameraDirection.X), 0)
* CFrame.new(0,0.4 + (-CameraDirection.Y/90*0.4),(-CameraDirection.Y/90*0.4))
end)
end)
Try placing it under “StarterCharacterScripts” instead, as it needs to run every time the Character is added.
Also this way there’s no need to bind it to “CharacterAdded”.
“StarterPlayerScripts” is for stuff that needs to run once, when the player joins (keep your persistent data there, player stats, player configs, etc.).
When it works, it should act like any first person camera with the special quality of making the head and its accessories transparent, but when I reset, the head and its accessories arent transparent anymore, as well not being in first person
Have you modified the script so that it doesnt listen for the CharacterAdded event, instead just sets the Character variable to the parent? If so, you might be having an interfering script, because any way i look at it, it should be working perfectly.
Also, dont use ipairs, pairs, because it is slower than just simply looping directly through the table.
Thats what Im thinking too, the script should be working fine but it flatout doesnt, and when the script was in the StarterCharacter, yes it was modified to not listen for the characteradded event
Actually, i looked through the script again, and it might be because the accessories havent actually loaded yet when the script tries connecting to their property changed signal, and the only reason it works on the first try, but not the seconds is becuase the game is loading and slows down the script enough to let them load before the script runs. This might be completely false but maybe try adding a task.wait(3) just to see if thats the case.