Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can anyone help me with welding a part onto a player's head?

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.

2 comments

0

I have tried setting the parent of newPart to the player's character but that results in it disappearing once the player zooms into first person.

0

I know that I should add a method of repeating the process when a new Character is created for each player but this is just for the purpose of testing.

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.