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?

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

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

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)

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

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

Answer this question