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

Trying to change a parts CFrame based on another parts CFrame. Help?

I am trying to put a piece of armor on to the players UpperTorso. So I'm creating a weld between an object that is in the exact center of the players UpperTorso and the armor piece. But I need the armor piece to be a couple of studs forward so that it's on the front of the players torso and not inside of it. I tried using CFrame but I believe I'm doing something wrong.

ArmorChest = game.ServerStorage.ArmorChest
ArmorConnect = game.ServerStorage.ArmorConnect

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent.UpperTorso:FindFirstChild("ArmorChest") then
		Char = hit.Parent
		ArmorClone = ArmorChest:Clone()
		ArmorChest.Parent = Char.UpperTorso
		ArmorConnectClone = ArmorConnect:Clone()
		ArmorConnectClone.Parent = Char
		ArmorConnectWeld = Instance.new("Weld")
		ArmorChestWeld = Instance.new("Weld")
		ArmorConnectWeld.Parent = Char
		ArmorChestWeld.Parent = Char
		ArmorConnectClone.CFrame = Char.UpperTorso.CFrame
		ArmorConnectWeld.Part0 = Char.UpperTorso
		ArmorConnectWeld.Part1 = Char.ArmorConnect
		ArmorClone.CFrame = (ArmorConnectClone.CFrame * CFrame.new(2,0,0))
		ArmorChestWeld.Part0 = Char.ArmorConnect
		ArmorChestWeld.Part1 = Char.UpperTorso.ArmorChest
	else
		
	end
end)

1 comment

0

Hey, I'm just change my answer.

1 answer

I think in line 18, instead of multiply the CFrame like this: ArmorClone.CFrame = (ArmorConnectClone.CFrame * CFrame.new(2,0,0))

It better to write like this: ArmorClone.CFrame = (ArmorConnectClone.CFrame + Vector3.new(2, 0, 0))

Because you want to make the armor 2 studs forward.

EDIT: You forgot to use CFrame:ToWorldSpace in line 15: ArmorConnectClone.CFrame = Char.UpperTorso.CFrame

You should write like this: ArmorConnectClone.CFrame = CFrame:ToWorldSpace(Char.UpperTorso.CFrame)

2 comments

0

That is also not working, but it also doesn't output an error.

0

It now gives this error: Workspace.EquipButton.Script:15: attempt to call method 'ToWorldSpace' (a nil value)

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