How can i attach something (like a flashlight) in the player's hand?

Hi developers,

I’m making a game called backrooms lost insanity; how can i attach a flashlight to the player’s hand? My game is not r15 and yes r6, but every time i try to attach something in the player’s hand, it just rotates in the wrong way. Can someone help me and give me some tips or something?

2 Likes

Hi, it might help to know how you’re attaching it or giving the code used to do the attachment.

2 Likes

I mean, i’m making the flashlight like play an animation, but i don’t want it to be a tool, i want to attach to the player’s hand, a long time ago, this didn’t worked idk why (the game was called escape from wonderland and i was making a flare, i tried to do that but it didn’t work, it was super bugged, the orientation wasn’t good, and it was bugged)

So is the flashlight a part of the animation, or are you using some constraint/weld to attach it to the player’s hand, or etc? You may be able to tinker with the CFrame or orientation in the code or constraint that creates the attachment, right?

I didn’t create any attachments, also i’m just asking for an example script (not a full one, just a example one for adding in my script)

You can play with a dummy (preferably copy some random walking script (check toolbox) to test how it moves the arm/hand along with the flashlight) and use a constraint/weld to keep the flashlight stuck on their hand then experiment with the properties. Then, to apply this to code, you’d need to copy the position/orientation of the flashlight or the properties of the constraint/weld. This is one easy way I can think of.

local flashlight = game:GetService("ServerStorage").Flashlight -- wherever it is
local function doStuff(hand)
    -- do your attachment stuff here w/ flashlight and hand
end

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local hand = character:WaitForChild("Right Arm")
        doStuff(hand)
    end)
end)
1 Like

If you use a tool, make sure RequiresHandle is ticked in its properties. Then, place a part in the tool and call it “Handle”. This is what the character will hold out, and it should stay there. You can rotate/scale as needed.

2 Likes

Thanks, but as i said in my post, i’m not making a tool, i’m trying to attach a part to the player’s hand

oops - I missed that line :sweat_smile:

But why not use a tool? Do you want it to be interactable? If it’s a torch/flashlight, why not?

Like @colorblindcrayon said, welds are the way to go.

1 Like

I don’t want to make a tool, i want to make just a simple flashlight that shows, because one of my scripts already show the arms and i don’t want a tool, because i want to make it so you can pick multiple things while having the flashlight equipped

You could use alignposition and alignorientation with an attachment inside of the players hand and then that way its not a tool and itll be able to follow the players hand position and keep its own orientation

This would also allow for automatic replication aswell, since those are replicated to all clients

just a question, what is a alignposition and alignorientation???

Basically they are constraints the like the name says allows you to position things and orient things using attachments

1 Like

Thanks, i might use that or not, thanks for the suggestion tho

1 Like

@colorblindcrayon It didn’t work buddy, It teleports to a completely other cframe, not on the grip one, how can i fix that?

here’s the code:

local hand = Character:WaitForChild("Right Arm")
				
				flashlightmeshclone.Parent = Character
				FlashlightMeshConnection = RunService.RenderStepped:Connect(function()
					flashlightmeshclone.CFrame = hand.RightGripAttachment.CFrame
				end)
				
				FlashlightAnimation:Play()

I don’t normally touch the RightGripAttachment but if it teleports to a completely other CFrame that probably means you’re using the wrong attachment?

I’ll suggest a different way. Use “WeldConstraint”, they both take in a Part0 and Part1 property. It doesn’t matter what order you do it in, just put one as the arm/hand and the other as the flashlight. Set the CFrame of the flashlight exactly how you’d want it to be and then have the constraints (the “WeldConstraint”) parented to the hand/arm. What this does is “lock” the position and orientation to the hand/arm. When the hand/arm moves, the flashlight moves at the same time which is the attachment part.

If you don’t know how to use those, look for tutorials and resources. If your flashlight is a model or multiple parts, you may need to create a “WeldConstraint” for each part in it.

This wouldn’t be a great way to do this … you would most likely be better off simply setting up a weld constraint. You could put everything in place so it is working as you wish with the weld inside the part. Then when you want it to be part of where you’re welding it too, just enable the weld.

Ok guys, thanks for all the helps, i’m gonna try some of them.

Why not create a Weld and change it’s C0 to rotate and stay in the way you want?

local weld = Instance.new("Weld")
weld.Part0 = Flashlight.PrimaryPart
weld.Part1 = Character.Hand

weld.C0 = CFrame.fromOrientation(0,0,0)
1 Like

i don’t think this will work, because i don’t want to attach the flashlight to the player’s arm, i want to attach to the player’s attachment right grip