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

Attempt to Index Upvalue?

Asked by 8 years ago
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!

0
You were checking ownername's value. HungryJaffer 1246 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
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)

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 carcanken 65 — 8y
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 carcanken 65 — 8y
Ad

Answer this question