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

How would I make the part stay in front of the torso, even after rotating the player?

Asked by 8 years ago

I'm not really what to use for this. The BodyPosition is what keeps it in place, 5 studs ahead.

wait()
local player=game.Players.LocalPlayer
local rs=game:GetService("RunService").RenderStepped

local p=Instance.new("Part", workspace)
print'Part'
p.FormFactor=Enum.FormFactor.Custom
p.BrickColor=BrickColor.new("Crimson")
p.Size=Vector3.new(1.5,1.5,1.5)
p.Material=Enum.Material.Neon
p.Transparency=.2
p.CanCollide=false
--
local sb=Instance.new("SelectionBox", p)
print'Selection Box'
sb.Adornee=p
sb.Color3=Color3.new(140,0,0)
sb.LineThickness=0.02
--
local bp=Instance.new("BodyPosition", p)
print'Body Position'
spawn(function()while true do
    bp.Position=player.Character.Torso.Position+Vector3.new(0,0,-5)
    rs:wait()
    end
end)

3 answers

Log in to vote
3
Answered by 8 years ago

There's a more comfortable answer for this

So, take your code. You see the line that says

bp.Position=player.Character.Torso.Position+Vector3.new(0,0,-5)

Now let's change it around a little so it gets the position of the CFrame of the torso.

wait()
local player=game.Players.LocalPlayer
local rs=game:GetService("RunService").RenderStepped

local p=Instance.new("Part", workspace)
print'Part'
p.FormFactor=Enum.FormFactor.Custom
p.BrickColor=BrickColor.new("Crimson")
p.Size=Vector3.new(1.5,1.5,1.5)
p.Material=Enum.Material.Neon
p.Transparency=.2
p.CanCollide=false
--
local sb=Instance.new("SelectionBox", p)
print'Selection Box'
sb.Adornee=p
sb.Color3=Color3.new(140,0,0)
sb.LineThickness=0.02
--
local bp=Instance.new("BodyPosition", p)
print'Body Position'
spawn(function()while true do
    bp.Position=(player.Character.Torso.CFrame*CFrame.new(0,0,-5)).p
    rs:wait()
    end
end)


Hope this helped!

~Chem

Ad
Log in to vote
1
Answered by 8 years ago

Instead on using a loop use a weld to keep the part in front of the player.

local weld = Instance.new("Weld",  game.JointsService)
w.C1 = PART2.CFrame:toObjectSpace(PART1.CFrame)
w.Part0 = PART1
w.Part1 = PART2
PART2.Anchored = false
PART1.Anchored = false

so what i did here is i created a new weld between the PART1 and PART2. next i modified the welds properties so that it would effectively keep the 2 in tact and then unacnhored them so that they can be moved. hope this helped

1
Took the words right out of my fingers. Well said lightpower26 399 — 8y
Log in to vote
-2
Answered by
yoshi8080 445 Moderation Voter
8 years ago

Here's what I did

1. I used a local script and put it in StarterGui

2. I used LocalPlayer.Character to get the character

3. I used a loop to keep the part's position

--// Gets player
local person = game.Players.LocalPlayer
--// Inserts a new part into player
part = Instance.new('Part',person.Character)
--// Edits part's properties
part.FormFactor = 'Custom'
part.Size = Vector3.new(1.5,1.5,1.5)
part.BrickColor = BrickColor.new("Crimson")
part.FormFactor = Enum.FormFactor.Custom
part.Material = Enum.Material.Neon
part.Transparency = .2
part.Anchored = true
part.CanCollide = false
--// Inserts selection box
box = Instance.new("SelectionBox",part)
box.Adornee = part
box.Color3 = Color3.new(140,0,0)
box.LineThickness=0.02
--// Makes part follow player
while wait() do 
part.Position = person.Character.Torso.CFrame * Vector3.new(0,0,-5) -- change to see how far you want it from your torso
end

I don't know how to make it follow your torso direction, so the rest is up to you

1
Or you could use a weld, which is much more efficient and won't lag. As well as it'll rotate with your torso lightpower26 399 — 8y

Answer this question