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

Please fix this Attempt to index nil error?

Asked by 3 years ago

There is an "Attempt to index nil with Value error. Can anyone please fix it?

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character:WaitForChild("Humanoid")
local IsSprinting = Player:WaitForChild("IsSprinting")
local Stamina = Player:WaitForChild("Stamina")

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Input,GameProcessed)
    if GameProcessed or Stamina == 0 then return end
    if Input.KeyCode == Enum.KeyCode.LeftShift then
        Humanoid.WalkSpeed = Character.Humanoid.WalkSpeed + 8
        IsSprinting.Value = true
    end
end)
UserInputService.InputEnded:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.LeftShift then
        Humanoid.WalkSpeed = Character.Humanoid.WalkSpeed - 8
        IsSprinting.Value = false
    end
end)

while wait() do
    if Stamina == 0 and IsSprinting.Value == true then
        IsSprinting = false
        Humanoid.WalkSpeed = 16
    end
    if IsSprinting.Value == true and Humanoid.MoveDirection.Magnitude > 0 then
        Stamina.Value = Stamina.Value - 1
        wait(1)
    else
        Stamina.Value = Stamina.Value + 1
        wait(1)
    end
    Stamina = math.clamp(Stamina.Value,0,100)
end
0
if GameProcessed or Stamina == 0 then return end ----needs to be----- if GameProcessed or Stamina.Value == 0 then return end WizyTheNinja 834 — 3y
0
Line 36 is contradictory, you'll overwrite the Object pointer. Ziffixture 6913 — 3y
0
See if all your Stamina have a .Value after them. All but line 6. 9mze 193 — 3y

Answer this question