Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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)


0
Humanoid won't be a value of the tool, you need to do Tool.Parent:FindFirstChild("Humanoid"), or script.Parent.Parent:FindFirstChild("Humanoid") Stephenthefox 94 — 5y
0
I have changed it. No change. How about you give me a script. appleprogamer_59 29 — 5y
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. Stephenthefox 94 — 5y
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. appleprogamer_59 29 — 5y
0
Add wait() on top of the script. User#22219 20 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
If this works then you learned something :) Sergiomontani10 236 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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) ~~~~~
0
I still get index upvalue 'Humanoid' (a nil value). This code did not do anything. appleprogamer_59 29 — 5y

Answer this question