How do I weld a spherical mesh to the players head?

I’m a very green scripter, so I’m gonna need some serious help on this one:

I’m trying to create a spherical mesh, make it around 500 x 500 x 500 studs, and then weld it to the players head so that the in-game fog actually interacts with the skybox instead of creating that weird terrain silhouette and then the skybox is clearly visible.

You can do that with following code:
local part = Instance.new("Part") - to create part itself
part.Parent = workspace - parent it to workspace
part.Size = Vector3.new(500, 500, 500) - to make it big
local mesh = Instance.new("SpecialMesh") - we create the mesh and parent it to the part
mesh.Parent = part - parent the mesh to our part
mesh.MeshType = Enum.MeshType.Sphere - now our part is an actual sphere
part.Position = workspace.(username).Head.Position - part’s position is the same as players’ head position. (username) is the username of the player.
local weld = Instance.new("Weld") - we create a weld
weld.Part0 = part
weld.Part1 = workspace.(username).Head- we have configured the weld.
:wink:
There are some more things to do, but you have to figure them out youself, as asking for full scripts is forbidden here.

Weld it to the HumanoidRootPart instead of the Head for a more accurate experience. The majority of your character work should be based around the root part.

Anyway. Should be as simple as creating the part and welding it to the player.

local fogProxy = Instance.new("Part")
fogProxy.Name = "FogPart"
fogProxy.BrickColor = BrickColor.new("Fog")
fogProxy.Size = Vector3.new(1, 1, 1)
fogProxy.Anchored = false
fogProxy.CanCollide = false
fogProxy.Massless = true
local fogMesh = Instance.new("SpecialMesh")
fogMesh.MeshId = "rbxassetid://1185246" -- Needed to invert the sphere
fogMesh.Scale = Vector3.new(-500, -500, -500)
fogMesh.Parent = fogProxy
local fogWeld = Instance.new("Weld")
fogWeld.Part0 = fogMesh
fogWeld.Part1 = Character.HumanoidRootPart -- Up to you to correct this
fogWeld.Parent = fogWeld.Part0
fogProxy.Parent = Character

The sphere needs to be inverted so that the player actually sees the sphere, otherwise without inversion the player will be in the sphere and thus will not be able to see it.

cc @pewpie12302die

WeldConstraints will weld in place, whereas other types of welds will snap at each part’s origin if not explicitly set. For this case, you’ll want a regular weld instead so you can avoid weird behaviours and the need to set position. Also, stay away from the parent argument of Instance.new.

2 Likes