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

I get the attempt to index upvalue 'Humanoid' (a nil value) in my tool script?

Basically I'm trying to make a drink that dose a animation and a sound effect and each time you drink it it makes your speed go up a tiny bit. When I try to run this code I get this error: attempt to index upvalue 'Humanoid' (a nil value) Please help me fix it here is the code:

local Tool = script.Parent;
local Humanoid = script.Parent:FindFirstChild("Humanoid")

enabled = true




function onActivated()
	if not enabled  then
		return
	end

	enabled = false
	Tool.GripForward = Vector3.new(-0, -0.836, -0.549)
	Tool.GripPos = Vector3.new(1.4, -0.4, 0.3)
	Tool.GripRight = Vector3.new(0.996, -0.0509, 0.0776)
	Tool.GripUp = Vector3.new(0.0928, 0.547, -0.832)


	Tool.Handle.DrinkSound:Play()

	wait(3)


	Tool.GripForward = Vector3.new(-.976,0,-0.217)
	Tool.GripPos = Vector3.new(0.2,-.1,0)
	Tool.GripRight = Vector3.new(.217,0,-.976)
	Tool.GripUp = Vector3.new(0,1,0)
wait(.5)
Humanoid.WalkSpeed = Humanoid.WalkSpeed +.5


	wait(5)
	enabled = true

end



script.Parent.Activated:connect(onActivated)


5 comments

0

Humanoid won't be a value of the tool, you need to do Tool.Parent:FindFirstChild("Humanoid"), or script.Parent.Parent:FindFirstChild("Humanoid")

0

I have changed it. No change. How about you give me a script.

0

That's not how this works, I'll fix it, but just keep in mind not to ask for the script, this is for help, not giving sciripts.

0

Auchally. This is how it works. You put a script and ask someone to help you fix it. By telling me the problem thats not really helping me how to fix it if I don't know how too.

0

Add wait() on top of the script.

2 answers

✓ Accepted answer

Try replacing

local Humanoid = Tool.Parent:FindFirstChild("Humanoid")

with

local Plr = game.Players.LocalPlayer

local Humanoid = Plr.Character:WaitForChild("Humanoid")

You should be also replace :connect() with :Connect() due to :connect() being deprecated.

1 comment

0

If this works then you learned something :)


local Tool = script.Parent;
local Humanoid = Tool.Parent:FindFirstChild("Humanoid")
local enabled = true




script.Parent.Activated:connect(function()
    if not enabled  then
    return
    end

    enabled = false
    Tool.GripForward = Vector3.new(-0, -0.836, -0.549)
    Tool.GripPos = Vector3.new(1.4, -0.4, 0.3)
    Tool.GripRight = Vector3.new(0.996, -0.0509, 0.0776)
    Tool.GripUp = Vector3.new(0.0928, 0.547, -0.832)


    Tool.Handle.DrinkSound:Play()

    wait(3)


    Tool.GripForward = Vector3.new(-.976,0,-0.217)
    Tool.GripPos = Vector3.new(0.2,-.1,0)
    Tool.GripRight = Vector3.new(.217,0,-.976)
    Tool.GripUp = Vector3.new(0,1,0)
wait(.5)
Humanoid.WalkSpeed = Humanoid.WalkSpeed +.5


    wait(5)
    enabled = true

end)


~~~~~

1 comment

0

I still get index upvalue 'Humanoid' (a nil value). This code did not do anything.

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