Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you attach blocks to players?

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?

local player = game.Players.LocalPlayer
local character = player.Character
local tool = script.Parent

function equip()
	local Ball = Instance.new("Part", character)
	Ball.Shape = "Ball"
	Ball.Size = Vector3.new(3,3,3)
	Ball.CanCollide = false
	local w = Instance.new("Weld", character)
	w.Part0 = Ball	
	w.Part1 = character.Torso
	Ball.Position = character.Head.Position +Vector3.new(3,1,0)	
end
tool.Equipped:connect(equip)

2 answers

✓ Accepted answer

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

local player = game.Players.LocalPlayer
local character = player.Character
local tool = script.Parent

function equip()
    local Ball = Instance.new("Part", character)
    Ball.Shape = "Ball"
    Ball.Size = Vector3.new(3,3,3)
    Ball.CanCollide = false
    local w = Instance.new("Weld", character)
    w.Part0 = character.Torso
    w.Part1 = Ball  
	w.c0 = CFrame.new((Character.Head.Position+Vector3.new(3,1,0)))-- c0 edited to match the Vector3 adjustments u wanted. 

end
tool.Equipped:connect(equip)

1 comment

0

Thank you! It worked, but I just needed to change c0 to C0

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.