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

Part weld on character spawn not working?

Asked by 8 years ago

I feel as if I am missing something, do I need to use C1? (even tho C1 didn't make a difference when I tested) I need help fixing up this script tho.

game:GetService("Players").PlayerAdded:connect(function(player)
       -- there is a part in game.Workspace named bigblock and you may replace :GetService("Players") with .Players if it makes your job easier to faster explain my script.
    player.CharacterAdded:connect(function(character)
    local part = game.Workspace:FindFirstChild("bigblock")
    part.Size = Vector3.new(8.8, 6.8, 8.2)
    part.Transparency = 0.75
    part.CanCollide = false
    local weld = Instance.new("Weld")
    local torso = character:WaitForChild("Torso")
    weld.Part0 = torso
    weld.C0 = torso.CFrame:inverse()
    weld.Part1 = part
    weld.Parent = part
    end)
end)

I use :inverse() so that the part may stick with the character's torso, the part is modified to have no cancollide, and it is not allowed to be anchored. Tell me if C1 is necessary for my script. Is the part not created properly or something? I even tried putting weld.Parent = part infront of the torso variable.

0
When I used C1, the line of code was weld.C1 = part.CFrame:inverse() AshRPG12 42 — 8y
0
Does this work? theCJarmy7 1293 — 8y
0
Try using the :WaitForChild("bigblock") instead of :FindFirstChild() iDev_Percy 45 — 8y
0
@iDev_Percy the bigblock doesn't need a waitforchild and using it doesn't work either AshRPG12 42 — 8y

1 answer

Log in to vote
0
Answered by
EgoMoose 802 Moderation Voter
8 years ago

The rule of thumb when it comes to welds is:

part0.CFrame * C0 == part1.CFrame * C1

If you re-arange this then you can easily solve for what you want. Your part0 is torso and your part1 is the brick you're trying to attach. Let's say you want the part to be attached directly to the centre of the torso (you were kind of ambigious as to what you wanted). Let's also assume we aren't using C1 b/c it's an offset point from C0 and only usually needed when you're animating joints. As such we can assume C1 is an empty cframe value (CFrame.new()) meaning when we multiply it by other cframes it changes nothing thereby allowing us to eliminate it from the above equation:

part0.CFrame * C0 == part1.CFrame

From here we can rearrange to solve for C0:

C0 = part0.CFrame:inverse() * part1.CFrame;

However, because you want part0 and part1 to both have the same world CFrame the two cancel out and leave us with CFrame.new(). The above equation would work with any world cframes though so feel free to use it.

0
After this, I looked at the wiki, I was pretty confused since I didn't know why you would do C0 == part1.CFrame or what it means because == means equal to commonly used in 'If's and I know it wouldn't mean making C0 equaling to part1.CFrame or turning it equal to part1.CFrame, but I also saw the wiki: http://wiki.roblox.com/index.php?title=Weld; There's a advanced one which I can probably edit eno AshRPG12 42 — 8y
0
Err, there's a advanced line of code in that wiki page, it is this: Part1.CFrame * C1 == Part0.CFrame * C0 (haven't tested) AshRPG12 42 — 8y
Ad

Answer this question