local characterHead = script.Parent:WaitForChild('Head') local newPart = Instance.new('Part') newPart.Size = Vector3.new(1,1,1) newPart.CanCollide = false newPart.Name = "Fog" local mesh = Instance.new('SpecialMesh') mesh.Scale = Vector3.new(-2000,-2000,-2000) mesh.Parent = newPart local weld = Instance.new('Weld') weld.Part0 = characterHead weld.Part1 = newPart newPart.CFrame = characterHead.CFrame newPart.Anchored = false weld.Parent = characterHead newPart.Parent = workspace
Here is a simple script I have made within StarterCharacterScripts of StarterPlayer. The purpose of the script is to create a weld which keeps a part in place, who's purpose is to add a fog effect. The problem which I am having is that whenever I zoom into first person, the part falls out of the map or just disappears. I am wondering if there is any way to fix this. I have already tried some things to fix this to no effect. Any help would be appreciated.
I think I narrowed it down to why. When your character loads, all of the properties below (things_that_break) change your head, which breaks the weld.
local characterHead = script.Parent:WaitForChild('Head') local update = tick() local things_that_break = { DraggingV1 = true; Position = true; Orientation = true; Rotation = true; } characterHead.Changed:connect(function(obj) if things_that_break[obj] then -- updates the last time something was changed in head update = tick() - update end end) while true do -- if the last time something was changed is more than -- .1 seconds ago, it's probably done initializing. if tick() - update > .1 then break end wait() end local newPart = Instance.new('Part') newPart.Size = Vector3.new(1,1,1) newPart.CanCollide = false newPart.Name = "Fog" local mesh = Instance.new('SpecialMesh') mesh.Scale = Vector3.new(-2000,-2000,-2000) mesh.Parent = newPart local weld = Instance.new('Weld', characterHead) weld.Part0 = characterHead weld.Part1 = newPart newPart.CFrame = characterHead.CFrame newPart.Parent = workspace