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.
01 | ArmorChest = game.ServerStorage.ArmorChest |
02 | ArmorConnect = game.ServerStorage.ArmorConnect |
03 |
04 | script.Parent.Touched:Connect( function (hit) |
05 | if hit.Parent:FindFirstChild( "Humanoid" ) and not hit.Parent.UpperTorso:FindFirstChild( "ArmorChest" ) then |
06 | Char = hit.Parent |
07 | ArmorClone = ArmorChest:Clone() |
08 | ArmorClone.Parent = Char.UpperTorso |
09 | ArmorConnectClone = ArmorConnect:Clone() |
10 | ArmorConnectClone.Parent = Char |
11 | ArmorConnectWeld = Instance.new( "Weld" ) |
12 | ArmorChestWeld = Instance.new( "Weld" ) |
13 | ArmorConnectWeld.Parent = Char |
14 | ArmorChestWeld.Parent = Char |
15 | ArmorConnectClone.CFrame = CFrame:ToWorldSpace(Char.UpperTorso.CFrame) |
It gives the following error, Workspace.EquipButton.Script:15: attempt to call method 'ToWorldSpace' (a nil value)
Sorry for the last answer does't work, I'm barely new to CFrame stuff.
Maybe this can help you *maybe : In line 15 change it into this:
1 | local offset = CFrame.new( 2 , 0 , 0 ) |
2 | ArmorConnectClone.CFrame = Char.UpperTorso.CFrame:ToWorldSpace(offset) |
And in line 18, you won't need to add some vector3 on it, so here some change:
ArmorClone.CFrame = ArmorConnectClone.CFrame
Hope it work, if it won't work, I got nothing to say : /