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

Am making a tycoon gives me nil values error?

Asked by
DevingDev 346 Moderation Voter
8 years ago

So, i am making a new tycoon where you have a gui and but stuffs not walk on buttons and i cant get this to work it gives me an nil value error and i dont know why heres the error

117:29:22.854 - Players.ObStactionD3stroy3r.PlayerGui.tycoonUI.frameTycoon.storeFolder.storeTycoon.base_item.buttonPurchase.buttonDriverTycoon:22: attempt to index global 'tycoon' (a nil value)
217:29:22.854 - Stack Begin
317:29:22.855 - Script 'Players.ObStactionD3stroy3r.PlayerGui.tycoonUI.frameTycoon.storeFolder.storeTycoon.base_item.buttonPurchase.buttonDriverTycoon', Line 22 - global onClick
417:29:22.855 - Script 'Players.ObStactionD3stroy3r.PlayerGui.tycoonUI.frameTycoon.storeFolder.storeTycoon.base_item.buttonPurchase.buttonDriverTycoon', Line 52

And heres the script.

01wait(0.5)
02item = script.Parent.Parent
03itemType = item.itemType.Value
04itemCost = item.itemCost.Value
05itemID = item.itemID.Value
06itemLocation = tostring(item.itemLocation.Value)
07itemName = tostring(item.itemName.Value)
08script.Parent.Parent.textName.Text = tostring(itemName).. ' | '.. tostring(itemCost).. ' Cash'
09 
10function onClick()
11    player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent
12 
13    cash = player.stats.Cash.Value
14 
15    tycoon = game.Workspace:FindFirstChild("tycoon_".. player.Name)
View all 52 lines...

1 answer

Log in to vote
1
Answered by 8 years ago

instead of doing this

1script.Parent.MouseButton1Click:connect(function()
2    if script.Parent.Parent.isItemPurchased.Value == false then
3        onClick()
4    end
5end)

do this

01script.Parent.MouseButton1Click:connect(function()
02    if script.Parent.Parent.isItemPurchased.Value == false then
03 player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent
04    cash = player.stats.Cash.Value
05    tycoon = game.Workspace:FindFirstChild("tycoon_".. player.Name)
06    print("type 1")
07    if itemType == 1 then
08        if cash >= itemCost then
09            itemGrab = tycoon.tycoonPurchases:FindFirstChild(itemLocation)
10            itemGrab.isPurchased.Value = true
11            script.Parent.Parent.isItemPurchased.Value = true
12        else
13            script.Parent.Text = "Not Enough Funds"
14            wait(3)
15            script.Parent.Text = 'Purchase'
View all 22 lines...
Ad

Answer this question