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

Using CFrame and welds for body armor but it isn't working. Any ideas?

Asked by 4 years ago

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()
        ArmorClone.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 = CFrame:ToWorldSpace(Char.UpperTorso.CFrame)
        ArmorConnectWeld.Part0 = Char.UpperTorso
        ArmorConnectWeld.Part1 = Char.ArmorConnect
        ArmorClone.CFrame = (ArmorConnectClone.CFrame + Vector3.new(2,0,0))
        ArmorChestWeld.Part0 = Char.ArmorConnect
        ArmorChestWeld.Part1 = Char.UpperTorso.ArmorChest
    else

    end
end)

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

1 answer

Log in to vote
2
Answered by 4 years ago

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:

local offset = CFrame.new(2,0,0)
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 : /

0
And yeah you can change the CFrame to fix it if it won't look right. Block_manvn 395 — 4y
1
No it still does not work. FallenZalio 99 — 4y
0
Does it throw some error Block_manvn 395 — 4y
0
Wait, let talk about this on community chat Block_manvn 395 — 4y
View all comments (2 more)
1
I figured it out. I had to change the C1 of the weld, not CFrame the part and then do the weld. FallenZalio 99 — 4y
0
Ok then Block_manvn 395 — 4y
Ad

Answer this question