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

How do you fix this error RightHand is not a valid member of Model?

So I am trying to make a punch script I have one in serverscriptserver and anther in something else.. The error im geting is: RightHand is not a valid member of Model. My code is:

math.randomseed(tick())
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = Instance.new("RemoteEvent", ReplicatedStorage)
punchEvent.Name = "PunchEvent"

local animations = {1594228609} --Custom Animations Here Or To Add Animation make {Your Id Here, Your Id Here}

local function onPunchFired(plr)
	local char = game.Workspace:FindFirstChild(plr.Name)
	local humanoid = char.Humanoid
	local animation = Instance.new("Animation")
	local picked = math.random(1, #animations)
	animation.AnimationId = "http://roblox.com/asset/?id="..animations[picked]
	local animTrack = humanoid:LoadAnimation(animation)
	animTrack:Play()
	local dmgScript = script.DmgScript:Clone()
	if picked == 1 then
		dmgScript.Parent = char.RightHand
	elseif picked == 2 then
		dmgScript.Parent = char.LeftHand
	end
	dmgScript.Disabled = false
	wait(0.4)
	dmgScript:Destroy()
end

punchEvent.OnServerEvent:Connect(onPunchFired)
---------------

If you know how to fix it please reply, thanks.

2 answers

Maybe you should replace line 9 with this..

local char = game.Players.LocalPlayer.Character

Hi, I don't know if you found the solution already or not but I was previously having the same problem. This stems from the event being called before the Character is loaded.

Solution:

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local char = player.Character

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