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?

repeat wait() until script.Parent.Product.Value~=nil
local product=script.Parent.Product.Value:clone()
script.Parent.Product.Value:remove()

local price=script.Parent.Price.Value

script.Parent.Head.Touched:connect (function(hit)
	chr=hit.Parent 
	if chr:findFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(chr) then
		plr=game.Players:GetPlayerFromCharacter(chr)
		if plr.Name==script.Parent.Parent.Parent.OwnerName.Value and plr.leaderstats.Money.Value>=price.Value then
			plr.leaderstats.Money.Value=plr.leaderstats.Money.Value-price
			product.Parent=script.Parent.Parent.Parent
		end
	end
end)

I receive the error "Workspace.Tycoon.Purchasing.Product - Price.Script:11: attempt to index upvalue 'price' (a number value)" when I try to test the script and I'm not entirely sure how to fix it as I'm working on learning lua, and I haven't entirely found an answer on google.

Thanks!

1 comment

0

You were checking ownername's value.

1 answer

✓ Accepted answer
repeat wait() until script.Parent.Product.Value ~= nil
local product = script.Parent.Product.Value:clone()
script.Parent.Product.Value:Destroy() -- remove is depricated, use destroy

local price = script.Parent.Price.Value

script.Parent.Head.Touched:connect (function(hit)
    chr = hit.Parent 
    if chr:findFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(chr) then
        plr = game.Players:GetPlayerFromCharacter(chr)
        if plr.Name == script.Parent.Parent.Parent.OwnerName and -- you tried to check if a numbervalue is nil, it doesn't work like that.
	    plr.leaderstats.Money.Value >= price.Value then
            plr.leaderstats.Money.Value = plr.leaderstats.Money.Value - price
            product.Parent = script.Parent.Parent.Parent
        end
    end
end)

2 comments

0

I don't see where I'm checking if a number value is nil, the script first verifies that you are the owner who claimed the tycoon->checks if your money is higher than the price which is specified in an int value->subtracts the money and spawns the product

0

I found out that I had pasted the script wrong, and the error instead lied on "and plr.leaderstats.Money.Value >=price.Value then" instead of the original line 11, so it looks like the OwnerName part was working fine. Sorry for not being clear about the issue

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