Is there a way to Set the position of a part on a specific point of another part

I tried to make a reload animation which required the model to grab a fake mag from behind and then put it inside the gun.

The problem is I don’t know how to position the fake mag so it is at the bottom of the left arm without having to do some precise calculation

image

the problem: (Magic Mag incident)

local debris = game:GetService("Debris")

local npc = script.Parent
local humanoid = npc.Humanoid
local Animator = humanoid.Animator

local Mag = game:GetService("ReplicatedStorage").Assets.etc.Magazine
local RealMag = npc["Test MP5"].Magazine

local idle = script.Idle
local reload = script.Reload

Animator:LoadAnimation(idle):Play()

while true do
	task.wait(10)
	local Fake = Mag:Clone()
	Fake.Transparency = 1
	Fake.Parent = workspace
	-- Insert position here --
	
	-----------------------------
	local Weld = Instance.new("WeldConstraint")
	Weld.Parent = npc["Left Arm"]
	Weld.Part0 = npc["Left Arm"]
	Weld.Part1 = Fake
	local track = Animator:LoadAnimation(reload)
	track:Play()
	track:GetMarkerReachedSignal("DropMag"):Connect(function()
		local Drop = Mag:Clone()
		Drop.Parent = workspace
		Drop.CFrame = RealMag.CFrame
		RealMag.Transparency = 1
		debris:AddItem(Drop, 3)
	end)
	track:GetMarkerReachedSignal("FakeMagVisible"):Connect(function()
		Fake.Transparency = 0
	end)
	
	track:GetMarkerReachedSignal("RealMagVisible"):Connect(function()
		Fake.Transparency = 1
		RealMag.Transparency = 0
	end)
	track.Stopped:Wait()
	Fake:Destroy()
	Weld:Destroy()
end

With what you want to achieve, it would be best to just have the fake mag animated too. And just toggle the visibility/transparency of the mags, instead of cloning the mag and positioning it in code.

There is another way, however you did mention you prefer not to do precise calculations to position the mag so just animating it is the easiest option.

some calculation is fine I just rather not going in depth if possible
please do tell some of another way I could achieve the same thing

Here is what I did, and you can play with the actual number if you want, but this should work.

I placed a local script in StarterCharacterScripts just for testing purposes

-- // Services

local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- // Variables

-- Get the "mag"
local fakeMag = ReplicatedStorage.Mag:Clone()

-- Get the character's left arm
local Character = script.Parent
local leftArm = Character:WaitForChild("Left Arm")

-- Create a weld
local Weld = Instance.new("Weld")
Weld.Part0 = fakeMag
Weld.Part1 = leftArm
Weld.Parent = fakeMag

fakeMag.CFrame = leftArm.CFrame -- Move the fake mag to the left arm
Weld.C0 = CFrame.new(0, leftArm.Size.Y / 2, 0) -- Position the weld so that it is on the bottom/hand of the left arm

-- I just place the mag inside the character here
fakeMag.Parent = Character

If you need more help or more explanation, feel free to ask. Tell me how this goes!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.