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

How do I create a "magic shield"?

Asked by 5 years ago
Edited 5 years ago

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 :

01local plr = script.Parent.Parent.Parent
02local char = plr.Character or plr.CharacterAdded:Wait()
03local p = Instance.new("Part",game.Workspace)
04active = false
05script.Parent.MouseButton1Click:Connect(function()
06        if char and not active then
07            local torso = char:WaitForChild("Torso")
08            active = true
09            p.Position = Vector3.new(torso.Position.X + 5,torso.Position.Y,torso.Position.Z)
10            p.Anchored = true
11            p.Size = Vector3.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)
0
You should look into Welding, and CFraming Fad99 286 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

1local part = Instance.new('Part',workspace)
2local torso = workspace.chloe_price65.Torso
3-- Assuming we are in r6
4part.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.
1
*cough* use the HumanoidRootPart not the Torso DeceptiveCaster 3761 — 5y
0
Did you read? SoftlockedUnderZero 668 — 5y
Ad

Answer this question