I want to create this shield that always appears in front of the player’s torso, but I don’t know how to always make it go a few studs away from the front of the player’s torso.
Here’s what I got :
01 | local plr = script.Parent.Parent.Parent |
02 | local char = plr.Character or plr.CharacterAdded:Wait() |
03 | local p = Instance.new( "Part" ,game.Workspace) |
04 | active = false |
05 | script.Parent.MouseButton 1 Click:Connect( function () |
06 | if char and not active then |
07 | local torso = char:WaitForChild( "Torso" ) |
08 | active = true |
09 | p.Position = Vector 3. new(torso.Position.X + 5 ,torso.Position.Y,torso.Position.Z) |
10 | p.Anchored = true |
11 | p.Size = Vector 3. new( 5 , 10 , 1 ) |
12 | p.Transparency = . 7 |
13 | p.Material = Enum.Material.Neon |
14 | wait( 10 ) |
15 | p:Destroy() |
16 | wait( 12 ) |
17 | active = false |
18 | end |
19 | end ) |
Each part has a CFrame value. Basically accounts for both position and orientation from the part’s perspective. CFrame is better for putting parts in front of your torso because it’s not based on world space. So if you use a position and orientation combo, you will end up with something messy because both properties don’t know where the front of your torso is.
1 | local part = Instance.new( 'Part' ,workspace) |
2 | local torso = workspace.chloe_price 65. Torso |
3 | -- Assuming we are in r6 |
4 | part.CFrame = torso.CFrame * --Goes to torso's position and |
5 | -- orientates to torso's orientation. |
6 | CFrame.new( 0 , 0 , 5 ) |
7 | -- Because we are in the torso's persective, you can sort of treat it as a vector3 value. |