zedix123
|
  |
| Joined: 29 Mar 2012 |
| Total Posts: 91 |
|
|
| 16 Jul 2015 08:10 PM |
This script is for a right arrow button to toggle the items on sale in a shop gui in order, the ShopSwordID is a stringValue, and the alphabet is it's value which identifies the item shown currently on the shop. (Like A = Sword1, etc. till E) Is there any way to restart this process?
------------------------------------------------------------------------------------- local AlphaTable = {"A","B","C","D","E"}
local n = script.Parent.Parent.ToggleVariable.Value -- linked to a NumberValue outside
function onClicked() script.Parent:FindFirstChild("ClickSound"):Play() n = n + 1 -- Adds 1 to the current table index position, (A to B, B to C etc.) script.Parent.Parent.ShopSwordID.Value = AlphaTable[n] -- The alphabet value of the string is changed. script.Parent.Parent.ToggleVariable.Value = n --return the current n value end
script.Parent.MouseButton1Down:connect(onClicked) -------------------------------------------------------------------------------------
Also, when I try "n = n - 1" (in line 7) for the left arrow, it doesn't work at all. Help? |
|
|
| Report Abuse |
|
|
zedix123
|
  |
| Joined: 29 Mar 2012 |
| Total Posts: 91 |
|
|
| 16 Jul 2015 08:14 PM |
I already took care of the restart cycle. But the left arrow still doesn't work. Just need help with that.
--Current Script:- local AlphaTable = {"A","B","C","D","E"}
local n = script.Parent.Parent.ToggleVariable.Value
function onClicked() if n < 5 then script.Parent:FindFirstChild("ClickSound"):Play() n = n + 1 script.Parent.Parent.ShopSwordID.Value = AlphaTable[n] script.Parent.Parent.ToggleVariable.Value = n elseif n == 5 then n = 1 script.Parent.Parent.ToggleVariable.Value = 1 script.Parent.Parent.ShopSwordID.Value = AlphaTable[n] end end
script.Parent.MouseButton1Down:connect(onClicked) |
|
|
| Report Abuse |
|
|
zedix123
|
  |
| Joined: 29 Mar 2012 |
| Total Posts: 91 |
|
| |
|
zedix123
|
  |
| Joined: 29 Mar 2012 |
| Total Posts: 91 |
|
|
| 16 Jul 2015 08:28 PM |
Output error.
06:28:08.062 - Players.Player1.PlayerGui.ShopGui.ShopContainer.ImageButton:8: bad argument #3 to 'Value' (string expected, got nil) 06:28:08.063 - Script 'Players.Player1.PlayerGui.ShopGui.ShopContainer.ImageButton', Line 8 |
|
|
| Report Abuse |
|
|
zedix123
|
  |
| Joined: 29 Mar 2012 |
| Total Posts: 91 |
|
|
| 16 Jul 2015 08:59 PM |
Fixed. Took an half an hour though.
local AlphaTable = {"A","B","C","D","E"}
local n = script.Parent.Parent.ToggleVariable
function onClicked() if n.Value < 5 then script.Parent:FindFirstChild("ClickSound"):Play() n.Value = n.Value + 1 -- Adds 1 to the current table index position, (A to B, B to C etc.) and variable value. script.Parent.Parent.ShopSwordID.Value = AlphaTable[n.Value] -- Check alphabet on current position of n (1 = A, 2 = B and onwards..) elseif n.Value == 5 then -- If viewing the last item, restart process on next click. script.Parent:FindFirstChild("ClickSound"):Play() n.Value = 1 -- Back to the first item script.Parent.Parent.ShopSwordID.Value = AlphaTable[n.Value] end end
script.Parent.MouseButton1Down:connect(onClicked) |
|
|
| Report Abuse |
|
|