Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My object will not attach to the right hand of the player can someone help me?

I am making a game where instead of tools the object is attached to your hand and it won't appear on the hand... Can someone explain to me how to fix this?

local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(player)
	local c = script.Parent:Clone()
	c.Parent = player.RightHand
end)

4 comments

0

This Is In A Script (Not Local) Inside Of The Object!

0

You set the parent, to set the position relative to the hand you have to do c:SetPrimaryPartCFrame(player.RightHand.CFrame)

0

but that's not the error the error is that it says "RightHand" isn't a part of Player

0

do player.Character.RightHand

3 answers

local w = instance.new("Weld", c)
w.Part0 = c
w.Part1 = RightHand
w.C0 = c.CFrame
w.C1 = RightHand.CFrame

3 comments

0

u can use it

0

Use "CFrame:Inverse()".

0

ye i forget

First off, you're trying to parent the tool to the Player. You need to parent the tool to the character. Second of all, to actually attach the tool to the right hand, you need to use a weld.

local weld = Instance.new("Weld")
w.Part0 = c
w.Part1 = player.Character.RightHand --assuming player is defined as the localplayer
weld.Parent = c

The character is a separate model from the player, so you must use player.Character.

Also, you have to set the clone's CFrame to the character's right hand's CFrame, and then add a WeldConstaint to it.


A WeldConstaint basically sticks a part to the character's right hand.

The Part0 and Part1 properties of a WeldConstraint are the parts you want to weld together.

You must also use the CharacterAdded event as the character gets destroyed when they've reset, including the part and weld.


Here's your fixed script:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local c = script.Parent:Clone()
		c.CFrame = character.RightHand.CFrame
		c.Parent = character.RightHand

		local weld = Instance.new("WeldConstraint")
		weld.Part0 = c
		weld.Part1 = character.RightHand
		weld.Parent = character.RightHand
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.