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)
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.
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) ~~~~~