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)
local w = instance.new("Weld", c) w.Part0 = c w.Part1 = RightHand w.C0 = c.CFrame w.C1 = RightHand.CFrame
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)