of     1   

Zelken
#227621032Friday, November 17, 2017 1:00 AM GMT

This is probably some beginner mistake but here's this script: --- Variables --- local plr = game.Players.LocalPlayer local skill = plr.Tradeskills:FindFirstChild(script.SkillName.Value) local skilllvl = script.SkillLevel.Value local Resource = plr.Tradeskills:FindFirstChild(script.ResourceName.Value) local RNeeded = script.Resource.Value local item = game.ReplicatedStorage.ITEMS:FindFirstChild(script.Parent.Parent.Name) --- Function --- script.Parent.MouseButton1Click:connect(function() if skill.Value >= skilllvl then if Resource.Value >= RNeeded then local itemclone = item:Clone() itemclone.Parent = plr.Backpack Resource = Resource - RNeeded end print(plr.Name.." doesn't have enough resources!") end print(plr.Name.."'s skill isn't high enough!") end) The error is in the title.
Cyrakohl
#227621082Friday, November 17, 2017 1:02 AM GMT

What line is the error on
Cyrakohl
#227621127Friday, November 17, 2017 1:03 AM GMT

It seems that you Indexed "skill" twice.
Voxxie
#227621166Friday, November 17, 2017 1:04 AM GMT

Hello Zelken! I'm assuming your instances like "script.SkillLevel" and "script.Resource" are IntValues, or something similar. Going off memory, you can not assign an instance's properties to a variable. ie: You can't do "local example = thing.Value" I'd recommend changing your variables to, for example, 'local skilllvl = script.SkillLevel', and then in your function referencing the value as 'skilllvl.Value'
TaaRt
#227621251Friday, November 17, 2017 1:07 AM GMT

You can do local example = thing.Value, it just won't change with thing's value nor will it change thing's value when altered as it's just a reference to the value it holds.
TaaRt
#227621321Friday, November 17, 2017 1:09 AM GMT

* as it's just a variable with the same value, not a reference to the original value at all
Zelken
#227621959Friday, November 17, 2017 1:28 AM GMT

@Cyrakohl It's on line 12
Zelken
#227622001Friday, November 17, 2017 1:30 AM GMT

@Voxxie I did that but it still doesn't work
TaaRt
#227622036Friday, November 17, 2017 1:31 AM GMT

Is it possible Resource returns nil? ( print(Resource) )
Preselect
#227622113Friday, November 17, 2017 1:34 AM GMT

This is unrelated, but another thing you should do is check if the player has enough money via the server. Just a safety precaution!
Zelken
#227622219Friday, November 17, 2017 1:38 AM GMT

Oh my bad it's on line 11. It has something to do with skilllvl
TaaRt
#227622308Friday, November 17, 2017 1:41 AM GMT

print skill, it's likely it returns nil
Zelken
#227622460Friday, November 17, 2017 1:46 AM GMT

No, skill didn't return nil
ZYRO2015_alt
#227622638Friday, November 17, 2017 1:51 AM GMT

--- Variables --- local plr = game.Players.LocalPlayer local skill = plr.Tradeskills:FindFirstChild(script.SkillName) local skilllvl = script.SkillLevel.Value local Resource = plr.Tradeskills:FindFirstChild(script.ResourceName.Value) local RNeeded = script.Resource.Value local item = game.ReplicatedStorage.ITEMS:FindFirstChild(script.Parent.Parent.Name) --- Function --- script.Parent.MouseButton1Click:connect(function() if skill.Value >= skilllvl then if Resource.Value >= RNeeded then local itemclone = item:Clone() itemclone.Parent = plr.Backpack Resource = Resource - RNeeded end print(plr.Name.." doesn't have enough resources!") end print(plr.Name.."'s skill isn't high enough!") end) served served
TaaRt
#227622650Friday, November 17, 2017 1:51 AM GMT

In general 'attempt to index upvalue' indicates you're trying to index a member that doesn't exist for whatever reason. Your best bet is to print all the things you're trying to index (a.something, a["something"] etc)
Zelken
#227622901Friday, November 17, 2017 2:00 AM GMT

Alright, I printed everything. Apparently Resource is nil.
Zelken
#227623035Friday, November 17, 2017 2:06 AM GMT

Ok I changed it and now it works
Rerumu
#227623074Friday, November 17, 2017 2:08 AM GMT

For future reference, upvalues are local variables in a different stack depth. local a = 5; function Something() local b = 4; print(a, b); --< "a" is an upvalue, but b isn't end;
TaaRt
#227623209Friday, November 17, 2017 2:13 AM GMT

@Shining, in this case the interpreter is assuming it's defined elsewhere (inaccessible) and thus providing that as likely reason?
Rerumu
#227623694Friday, November 17, 2017 2:30 AM GMT

Upvalues work the same as locals, but they just are defined out of scope because of how bytecode needs to be compiled. Just referring to the fact one should be looking out of stack.
TaaRt
#227623899Friday, November 17, 2017 2:38 AM GMT

Ah ok, along with the lua docs that does make sense, never really stopped to consider the way scoping works in compilation. Thank you for elaborating

    of     1