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

How do you attach blocks to players?

Asked by 8 years ago
Edited 8 years ago

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?

01local player = game.Players.LocalPlayer
02local character = player.Character
03local tool = script.Parent
04 
05function equip()
06    local Ball = Instance.new("Part", character)
07    Ball.Shape = "Ball"
08    Ball.Size = Vector3.new(3,3,3)
09    Ball.CanCollide = false
10    local w = Instance.new("Weld", character)
11    w.Part0 = Ball 
12    w.Part1 = character.Torso
13    Ball.Position = character.Head.Position +Vector3.new(3,1,0)
14end
15tool.Equipped:connect(equip)

2 answers

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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

01local player = game.Players.LocalPlayer
02local character = player.Character
03local tool = script.Parent
04 
05function equip()
06    local Ball = Instance.new("Part", character)
07    Ball.Shape = "Ball"
08    Ball.Size = Vector3.new(3,3,3)
09    Ball.CanCollide = false
10    local w = Instance.new("Weld", character)
11    w.Part0 = character.Torso
12    w.Part1 = Ball 
13    w.c0 = CFrame.new((Character.Head.Position+Vector3.new(3,1,0)))-- c0 edited to match the Vector3 adjustments u wanted.
14 
15end
16tool.Equipped:connect(equip)
0
Thank you! It worked, but I just needed to change c0 to C0 beatersz 25 — 8y
Ad
Log in to vote
0
Answered by
Bertox 159
8 years ago
Edited 8 years ago

You can't re-position the Ball when you use weld

1local Weld = Instance.new("Weld")
2Weld.Parent = Ball
3Weld.Part0 = character.Head --Weld to head instead to torso
4Weld.Part1 = Ball

Answer this question