So I’m trying to make the hat invisible when I go in first-person, but the only way I was able to do so was by doing :Remove(), but when I return it, the hat’s children are gone, resulting in the hat not being there and the camera glitching out.
It’s in the hidehats function in the code:
wait(0.5)
local handle = script.Parent.Handle
local char = game.Players.LocalPlayer.Character
local camera = workspace.CurrentCamera
local playeer = game.Players.LocalPlayer
seat = game.Players.LocalPlayer.Character.looke
local RunService = game:GetService("RunService")
function hideHats()
for _, v in pairs(char:GetChildren()) do
if v.ClassName == "Accessory" and v.AccessoryType == Enum.AccessoryType.Hat then
v:Remove()
print("hat")
wait(3)
for _, child in pairs(v:GetChildren()) do
child.Parent = char
print(child.Parent)
end
--v.Parent = char
end
end
end
script.Parent.Equipped:Connect(function()
--seat = script.Parent.Parent["Right Arm"]
char.Torso["Right Shoulder"].Enabled = false
char.Torso.alig.Enabled = true
end)
script.Parent.Unequipped:Connect(function()
char.Torso["Right Shoulder"].Enabled = true
char.Torso.alig.Enabled = false
end)
RunService.RenderStepped:Connect(function()
local camCF = camera.CFrame
seat.CFrame = camera.CFrame - camera.CFrame.Position + seat.Position;
--seat.CFrame = CFrame.new(seat.Position, camera.CFrame.Position)*CFrame.Angles(0, math.rad(180), 0)
end)
local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
camera.CameraSubject = char.CamSub2
char.Torso.Bodyturn.Enabled = true
hideHats()
camera.FieldOfView = 90
playeer.CameraMinZoomDistance = 0.6
playeer.CameraMaxZoomDistance = 0.6
char.turne.Turn.TargetAngle = 45
--handle.Turn.TargetAngle = 47
end
end)
userInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
camera.CameraSubject = char.CamSub1
char.Torso.Bodyturn.Enabled = false
camera.FieldOfView = 60
playeer.CameraMaxZoomDistance = 5
playeer.CameraMinZoomDistance = 5
char.turne.Turn.TargetAngle = 0
--handle.Turn.TargetAngle = 0
end
end)
RunService:BindToRenderStep("MouseLock",Enum.RenderPriority.Last.Value+1,function()
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end)
I don’t actually know what I’m doing in the function at all fyi