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

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

Asked by
zpfran -25
4 years ago

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)
0
This Is In A Script (Not Local) Inside Of The Object! zpfran -25 — 4y
0
You set the parent, to set the position relative to the hand you have to do c:SetPrimaryPartCFrame(player.RightHand.CFrame) blowup999 659 — 4y
0
but that's not the error the error is that it says "RightHand" isn't a part of Player zpfran -25 — 4y
0
do player.Character.RightHand blowup999 659 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago
local w = instance.new("Weld", c)
w.Part0 = c
w.Part1 = RightHand
w.C0 = c.CFrame
w.C1 = RightHand.CFrame
0
u can use it Ariya1234gamer 15 — 4y
0
Use "CFrame:Inverse()". youtubemasterWOW 2741 — 4y
0
ye i forget Ariya1234gamer 15 — 4y
Ad
Log in to vote
0
Answered by
zadobyte 692 Moderation Voter
4 years ago

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
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)

Answer this question