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

Attempt to index nil with 'RightHand' (?)

If this is easy to solve, I'm sorry for asking a really stupid question.

I'm trying to clone to RightHandHitBox, which is a (model with a rig that will be attached to the player's Right Hand) into the player's Right Hand once they join the game.

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

Players.PlayerAdded:Connect(function(Player)
	game.ReplicatedStorage.Server2Client.Intro:FireClient(Player)
	
	local Character = Player.Character
	wait(2)
	local RightHandHitBox = ServerStorage.RightHandHitBox:Clone()
	RightHandHitBox.Parent = Character.RightHand
end)

When it has to run that line of code it says ServerScriptService.Script:10: attempt to index nil with 'RightHand'

May I have some assistance to successfully put the model in the right hand?

RightHandHitBox in Explorer RightHandHitBox's Properties

1 answer

✓ Accepted answer

the problem is actually caused by local Character = Player.Character... when the player is added to the game, their character might not be loaded already, therefore, you need to do:

local character = player.Character or player.CharacterAdded:Wait(); so here is your code revised:

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

Players.PlayerAdded:Connect(function(Player)
    game.ReplicatedStorage.Server2Client.Intro:FireClient(Player)

    local character = Player.Character or Player.CharacterAdded:Wait();
    wait(2)
    local RightHandHitBox = ServerStorage.RightHandHitBox:Clone()
    RightHandHitBox.Parent = Character.RightHand
end)

1 comment

0

Thanks!

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