Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
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.

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. iishadowflames 41 — 7y
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. iishadowflames 41 — 7y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

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

Ad

Answer this question