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

weld goes away when i rotate the part ?

Asked by 6 years ago

Hello, the title says it all i made a script that welds a part to your head and i want this part to rotate but it just keeps falling down when it starts rotating

The script:

crystal = game.Lighting.Crystal

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        local head = char.Head
        local crystalClone = crystal:Clone()
        crystalClone.Parent = char

        local Weld = Instance.new('Weld', head)
        Weld.C0 = head.CFrame + Vector3.new(0,-17.5,-22.5)
        Weld.Part0 = head
        Weld.Part1 = crystalClone

        while true do
            for i = -90, 180 do
                crystalClone.Orientation = Vector3.new(0,i,0)
                wait(0.01)
            end
        end

    end)
end)

does anyone know a way so it doesn't fall down ? thanks!

0
you can change the orientation of the weld by changing it's cframe, that could work.. User#20388 0 — 6y
0
If i do that the whole player that its welded to starts turning to TigerClaws454 48 — 6y

2 answers

Log in to vote
2
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

You can solve this issue by using WeldConstraints, the new method for welding on Roblox.

Before WeldConstraints were added, Welds were used to attach things together. As these required two different CFrame offsets to determine the location of one part relative to the other, they were slightly complicated to use. However, the introduction of WeldConstraints makes welding super simple and fun!

When you want to weld one part to another, there are 3 main steps:

1. Move the part you want to weld to the position you want to weld it to (often by setting its CFrame).

2. Create the WeldConstraint and put it in the part.

3. Set the Part0 property of the WeldConstraint to the first part, and the Part1 property of the WeldConstraint to the second part.

For example, if you wanted to weld a piece of armour (such as a chestplate) to the character, all you have to do is follow these steps. If you have a copy of the armour inside ReplicatedStorage and called it Armour, the script might look something like this:

local function EquipArmour(Char,Armour)
    local NewArmour = Armour:Clone() 
    local Root = Char:WaitForChild("HumanoidRootPart") --set root part of the character

    NewArmour:SetPrimaryPartCFrame(Root.CFrame) --1. Move armour to character

    local Weld = Instance.new("WeldConstraint") --2. create weld

    Weld.Part0 = NewArmour.PrimaryPart --3. set weld Part0
    Weld.Part1 = Root --3. set weld Part1

    Weld.Parent = NewArmour
    NewArmour.Parent = Character
end

local Armour = game:GetService("ReplicatedStorage").Armour
--Give armour to player when they join:
game.Players.PlayerAdded:Connect(function(Plr)
    Plr.CharacterAdded:Connect(function(Char)
        EquipArmour(Char,Armour)
    end)
end)

This example work the same way for your crystal part. However, when you set the orientation, it will remain connected to your character, not breaking the weld.

Hope this helps!

0
Thank you !!! TigerClaws454 48 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The weld is programmed to break whenever one of it's parts moves (this includes with position, orientation, size, etc.) You COULD try making a new weld every time the part is rotated. Like so:

crystal = game.Lighting.Crystal

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        local head = char.Head
        local crystalClone = crystal:Clone()
        crystalClone.Parent = char

        local Weld = Instance.new('Weld', head)
        Weld.C0 = head.CFrame + Vector3.new(0,-17.5,-22.5)
        Weld.Part0 = head
        Weld.Part1 = crystalClone

        while true do
        for i = -90, 180 do
            crystalClone.Orientation = Vector3.new(0,i,0)
             -- Make the new weld
            local Weld = Instance.new('Weld', head)
            Weld.C0 = head.CFrame + Vector3.new(0,-17.5,-22.5)
            Weld.Part0 = head
            Weld.Part1 = crystalClone

            wait(0.01)
        end
        end)
end)

Constraints are a little confusing, so forget about Weld Constraints.

0
doesn't work the weld doesn't appear :/ TigerClaws454 48 — 6y
0
Don't discourage the use of something just because you dont understand how it works. mattscy 3725 — 6y
0
They are confusing, and very hard to learn. If you have several weeks' worth of time to study constraints, cool, but not everyone has that. GamingZacharyC 152 — 6y

Answer this question