Okay, so I wanted the ball to follow the player, and move with the torso, so I welded it. But the weld isn't working because the ball isn't close enough to the torso I think. Is there a way to attach the ball to the torso so that it moves with it?
01 | local player = game.Players.LocalPlayer |
02 | local character = player.Character |
03 | local tool = script.Parent |
04 |
05 | function equip() |
06 | local Ball = Instance.new( "Part" , character) |
07 | Ball.Shape = "Ball" |
08 | Ball.Size = Vector 3. new( 3 , 3 , 3 ) |
09 | Ball.CanCollide = false |
10 | local w = Instance.new( "Weld" , character) |
11 | w.Part 0 = Ball |
12 | w.Part 1 = character.Torso |
13 | Ball.Position = character.Head.Position +Vector 3. new( 3 , 1 , 0 ) |
14 | end |
15 | tool.Equipped:connect(equip) |
As Bertox said, editing the position is worthless when you are working with Welds
Instead, you need to alter a property of Welds
which is c0
. This is essentially the CFrame offset of the weld, and determines where Part1 will be in relation to Part0.
w.c0 = CFrame.new((Character.Head.Position+Vector3.new(3,1,0))
is the code you'd use
Let me know if this works for you
01 | local player = game.Players.LocalPlayer |
02 | local character = player.Character |
03 | local tool = script.Parent |
04 |
05 | function equip() |
06 | local Ball = Instance.new( "Part" , character) |
07 | Ball.Shape = "Ball" |
08 | Ball.Size = Vector 3. new( 3 , 3 , 3 ) |
09 | Ball.CanCollide = false |
10 | local w = Instance.new( "Weld" , character) |
11 | w.Part 0 = character.Torso |
12 | w.Part 1 = Ball |
13 | w.c 0 = CFrame.new((Character.Head.Position+Vector 3. new( 3 , 1 , 0 ))) -- c0 edited to match the Vector3 adjustments u wanted. |
14 |
15 | end |
16 | tool.Equipped:connect(equip) |
You can't re-position the Ball when you use weld
1 | local Weld = Instance.new( "Weld" ) |
2 | Weld.Parent = Ball |
3 | Weld.Part 0 = character.Head --Weld to head instead to torso |
4 | Weld.Part 1 = Ball |