Help with getting a part "anchored" to a players character

  1. What do you want to achieve? Hello, Developers! I am inserting a part into the players character, but I can’t seem to figure out how to make it move with the player

  2. What is the issue? The issue is that the part cloned and put into the players character doesn’t move with their character

  3. What solutions have you tried so far? I looked on YouTube and the Developer Forum

In my script I have a part in ReplicatedStorage named “CameraPart” and I am cloning it and inserting it into the players character. The only thing is that the part doesn’t move with the character, it just stays were it spawned.

Here is my code:

local player = game.Players.LocalPlayer
local camera = game.ReplicatedStorage:WaitForChild("CameraPart")

function insertCamera()
	local char = player.Character
	camera:Clone()
	camera.Parent = char
	camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0,-.5,5)
	camera.Anchored = true
	camera.CanCollide = false
end

wait(1)
insertCamera()

Video:
withoutWeld.wmv (1.4 MB)

Then I though I could create a weld so it follows the character, but that didn’t work. It only teleported the players character into the part.

Here is the code:

local player = game.Players.LocalPlayer
local camera = game.ReplicatedStorage:WaitForChild("CameraPart")

local weld = Instance.new("Weld")

function insertCamera()
	local char = player.Character
	camera:Clone()
	camera.Parent = char
	camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0,-.5,5)
	camera.Anchored = true
	camera.CanCollide = false
	weld.Parent = char.CameraPart
	weld.Part1 =  char.CameraPart
	weld.Part0 = char.UpperTorso
end

wait(1)
insertCamera()

Video:
withWeld.wmv (1.1 MB)

This may be a simple fix but, with my beginner coding knowledge, I can’t seem to figure it out!

1 Like

Oh, and I forgot to say, but the script is running in StarterPlayerScripts

You are anchoring the camera, “camera.Anchored = true”. Try changing this to false and see if that solves your issue. :+1:

Oh yeah, that’s right. But I tried and it works, but the part is inside the character when I want it 5 studs out on the z-axis

you have to offset the weld by the Z axis not the part itself

1 Like

is this what it’s supposed to look like?

One thing I’d like to mention is that there is no reference to the clone , for example

local camClone = camera:Clone()

all the properties you are changing are from the original block , not the clone you made

camera:Clone()
	camera.Parent = char
	camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0,-.5,5)
	camera.Anchored = true
	camera.CanCollide = false

ok, so I should have the clone as a local and change the properties that way?

1 Like

And yes thats what its supposed to look like, and thank you so much for your help

1 Like

yes! the script should look like this

local player = game.Players.LocalPlayer
local camera = game.ReplicatedStorage:WaitForChild("CameraPart")
local weld = Instance.new("Weld")

function insertCamera()
	local char = player.Character
	local camClone = camera:Clone()
	camClone.Parent = char
	camClone.Anchored = false
	camClone.CanCollide = false
	weld.Parent = camClone
	weld.Part1 =  camClone
	weld.Part0 = char.UpperTorso
	weld.C1 = CFrame.new(0,-.5,5)
end

wait(1)
insertCamera()
1 Like