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

Attempt to Index Upvalue (a nil value)?

Asked by 8 years ago
local OwnerName = script.Parent.Parent.Parent.Owner
local MoneyStorage = game:GetService('ServerStorage').MoneyStorage
local Money = MoneyStorage:FindFirstChild(OwnerName)
local Injuries = script.Parent.Parent.Parent.Injuries
local InjuryRate = script.Parent.InjuryRate
local MoneyLostOnLawsuit = script.Parent.MoneyLostOnLawsuit

function Lawsuit()
    if script.Parent.MachineOn.Value == true then
        MoneyLostOnLawsuit.Value = Money.Value - (Money.Value * ((Injuries.Value * InjuryRate.Value)/1000)) 
        Money.Value = Money.Value - MoneyLostOnLawsuit.Value
        print ("Money lost in lawsuit: " .. MoneyLostOnLawsuit.Value)
        OwnerName.Value.PlayerGui.LawsuitPopup.TextButton.Visible = true       
        OwnerName.Value.PlayerGui.LawsuitPopup.TextButton.Text = ("You have recently been sued due to injuries caused by your medication! Money Lost: " .. MoneyLostOnLawsuit.Value .." Prevent this by researching methods of protection!")
        wait (0.1)
    else
        print ("Machine is off, lawsuit will not occur!")
        wait (0.1)
    end
end



wait (10)
Lawsuit()

When this script runs I get an Index Upvalue 'Money' ( a nil value) error on the line "MoneyLostOnLawsuit.Value = Money.Value-(Money.Value * ((Injuries.Value * InjuryRate.Value)/1000))

Is this happening because I reference Money.Value twice?

I dont really see how this isn't working and if somebody could give some insight that would be great.

Thank you!

1 answer

Log in to vote
1
Answered by 8 years ago

Most likely it is because of lines 1-3. Change it to this:

local OwnerName=script.Parent.Parent.Parent.Owner
local MoneyStorage=game.ServerStorage:WaitForChild("MoneyStorage")
local Money=MoneyStorage:WaitForChild(OwnerName.Value)

Hope this helped!

0
I tried this solution and I get a "Arguement missing or nil" error. carcanken 65 — 8y
0
Okay, try adding the WaitForChild() to line 1. ChipioIndustries 454 — 8y
Ad

Answer this question