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!
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!
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
.