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

How to use Part.Position + Vector3.new?

Asked by 6 years ago
Edited 6 years ago

So I'm trying to make a grenade that you hold in your hand without using the tool. Everything works, except for when you hold it. It stays in the same position like I never added the extra Vector3. Could someone help? Thanks!

Here's the script:

    local Grenade = game.ServerStorage.Grenade:Clone()
    local Motor = Instance.new("Motor6D")
    Grenade.Parent = game.Workspace
    Grenade.Position = plr.Character["Right Arm"].Position + Vector3.new(0, 50, 0) -- This is where I'm having problems.
    print(Grenade.Position)
    Motor.Parent = Grenade
    Motor.Part0 = Grenade
    Motor.Part1 = plr.Character["Right Arm"]

EDIT: The position does change when I take out the + Vector3 and add it in but it still stays in the same position. Why??

0
I've got quite a bit to learn with CFrames, but I believe you're going to want to change the C0 and C1 properties of the motor as opposed to trying to change the grenade's position. 'C0' and 'C1' would respectively be the offset point for both the grenade 'Part0' and the right arm 'Part1'. caoshen 96 — 6y
0
Use coordinateframes instead of vector3. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
1
Answered by
caoshen 96
6 years ago

I gave it a shot myself and came up with this, which seems to work. So as stated by the Wiki, C0 is how the offset point is attached to Part0 which is the player's right (lower) arm in this case, and C1 is subtracted from C0 to create the offset point for Part, the grenade.

In this example, the offset point for the grenade is just a little under the hand.

local RBX_P = game:GetService("Players");
local RBX_W = game:GetService("Workspace");

local grenadeModel = RBX_W:WaitForChild("Grenade");

RBX_P.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        wait(2.5);

        local rightArm = character:WaitForChild("RightLowerArm");

        local grenade = grenadeModel:Clone();
        grenade.Parent = character;

        local motor = Instance.new("Motor6D");
        motor.Part0 = rightArm;
        motor.Part1 = grenade
        motor.C0 = rightArm.CFrame;
        motor.C1 = motor.C0 * CFrame.new(0, 1.1, 0.25);
        motor.Parent = rightArm
    end)
end)

This is what it looks like in-game.

0
Thank you so much! It works perfectly! The only problem is, is I don't know how to rotate it while it's in the player's hand since I don't know CFrame that well. Is there a way to rotate the part using CFrame when it gets cloned to the player's hand? ragingskull182 67 — 6y
0
After CFrame.new(0, 1.1, 0.25) add * CFrame.Angles(0, 0, 0) and play around until you get something you like. Make sure you convert the value to radians using math.rad() first though. caoshen 96 — 6y
0
I also believe there's a post about CFrames; click 'Guides' on the page's navigation and you should find it by 'jobro13'. caoshen 96 — 6y
0
Oh okay. Thanks again! ragingskull182 67 — 6y
Ad

Answer this question