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

Attempt to Index Upvalue (a nil value)?

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

✓ Accepted answer

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!

2 comments

0

I tried this solution and I get a "Arguement missing or nil" error.

0

Okay, try adding the WaitForChild() to line 1.

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