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 local 'hit' (a nil value)" ?

in this script i get this error that you see in title and i dont know why

this is in a normal script in workspace

wait(2)
local Damage = 1
me = game.Players.LocalPlayer
Playa = game.Players.LocalPlayer
mouse = me:GetMouse()
Torso = me.Character.Torso
Head = me.Character.Head
Humanoid = me.Character.Humanoid
Neck = Torso["Neck"]
RightShoulder = Torso["Right Shoulder"]
LeftShoulder = Torso["Left Shoulder"]
RightHip = Torso["Right Hip"]
LeftHip = Torso["Left Hip"]
LeftArm = me.Character["Left Arm"]
RightArm = me.Character["Right Arm"]
LeftLeg = me.Character["Left Leg"]
RightLeg = me.Character["Right Leg"]
req = 50


-- Damage
function Damage1(hit)
if hit.Parent:findFirstChild("Humanoid") and hit.Parent.Name ~= me.Name then
hit.Parent.Humanoid:TakeDamage(3)
wait(.2)
end
end


---- C MOVE--
PlayzUf = Playa.Name 
CMoveCD = true
mouse.KeyDown:connect(function(Key)
if Key == "r" and CMoveCD == true  and Humanoid.Jump == false then
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/item.aspx?id=321445347"
local animTrack = Humanoid:LoadAnimation(animation)
local Damage = 1
animTrack:Play()
wait(2)
local Damage = 0
end
end)
if Damage == 1 then
	Damage1()
end

2 comments

0

Line 45: Your missing an argument. Try replace it with Damage1(me.Character)

0

Can your provide more information? Such as what is suppose to happen, if this is a Script or Local Script. What is actually happening, and what part is suppose to be touched to be damaged. I see multiple things wrong and I need more information to help.

1 answer

✓ Accepted answer

MOST CREDIT TO fahmisack123 FOR COMMENTING THE PROBLEM. Ok, as fahmisack123 said, you're missing the argument on line 45, in your parenthesis you have nothing, but the function requires an argument called hit, when you just fire the function it tries to find a humanoid in nothing therefore breaking. This has a simple fix, just add me.Character inside the parenthesis like so:

wait(2)
local Damage = 1
me = game.Players.LocalPlayer
Playa = game.Players.LocalPlayer
mouse = me:GetMouse()
Torso = me.Character.Torso
Head = me.Character.Head
Humanoid = me.Character.Humanoid
Neck = Torso["Neck"]
RightShoulder = Torso["Right Shoulder"]
LeftShoulder = Torso["Left Shoulder"]
RightHip = Torso["Right Hip"]
LeftHip = Torso["Left Hip"]
LeftArm = me.Character["Left Arm"]
RightArm = me.Character["Right Arm"]
LeftLeg = me.Character["Left Leg"]
RightLeg = me.Character["Right Leg"]
req = 50


-- Damage
function Damage1(hit)
if hit.Parent:findFirstChild("Humanoid") and hit.Parent.Name ~= me.Name then
hit.Parent.Humanoid:TakeDamage(3)
wait(.2)
end
end


---- C MOVE--
PlayzUf = Playa.Name 
CMoveCD = true
mouse.KeyDown:connect(function(Key)
if Key == "r" and CMoveCD == true  and Humanoid.Jump == false then
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/item.aspx?id=321445347"
local animTrack = Humanoid:LoadAnimation(animation)
local Damage = 1
animTrack:Play()
wait(2)
local Damage = 0
end
end)
if Damage == 1 then
    Damage1(me.Character) -- These parenthesis used to be empty.
end

If this helped you, please vote up and accept this as the answer but most of the credit goes to fahmisack123.

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