Item Shop Cycler for GUI Dying whenever i run it?

Im trying to make an item sorter gui type, where it has a next and previous button, and i keep running against no errors in the output and just fails everytime

local previous = script.Parent.Parent.Left
local Next = script.Parent.Parent.Right
local currentitem = 1
local finished = nil

Next.MouseButton1Click:Connect(function()
	script.Parent.Parent.Bubble.Chat1.Visible = false
	if currentitem > 6 then
		currentitem = 1
	else
	currentitem = currentitem + 1
		for i,v in ipairs(script.Parent:GetChildren()) do
			if v:IsA("Frame") and v.Name == not currentitem then
				v.Visible = false
				v:WaitForChild("LocalScript").Enabled = false
			end
		end
	end
	for i,v in ipairs(script.Parent:GetChildren()) do
		if v:IsA("Frame") and v.Name == currentitem then
			v.Visible = true
			v:WaitForChild("LocalScript").Enabled = true
		end
	end	
end)

previous.MouseButton1Click:Connect(function()
	script.Parent.Parent.Bubble.Chat1.Visible = false
	if currentitem < 1 then
		currentitem = 6
	else
		currentitem = currentitem - 1
		for i,v in ipairs(script.Parent:GetChildren()) do
			if v:IsA("Frame") and v.Name == not currentitem then
				v.Visible = false
				v:WaitForChild("LocalScript").Enabled = false
			end
		end
	end
	for i,v in ipairs(script.Parent:GetChildren()) do
		if v:IsA("Frame") and v.Name == currentitem then
			v.Visible = true
			v:WaitForChild("LocalScript").Enabled = true
		end
	end	
end)

image
image

You probably just need to change this to

if v:IsA("Frame") and v.Name == tostring(currentitem) then

but if you wanted to tidy up your code a little to make it more manageable then:

local previous = script.Parent.Parent.Left
local Next = script.Parent.Parent.Right
local currentitem = 1
local finished = nil

local function ShowItem()
	
	script.Parent.Parent.Bubble.Chat1.Visible = false
	for i,v in ipairs(script.Parent:GetChildren()) do
		if v:IsA("Frame") then
			if v.Name ==  tostring(currentitem) then
				v.Visible = true
				v:WaitForChild("LocalScript").Enabled = true
			else
				v.Visible = false
				v:WaitForChild("LocalScript").Enabled = false
			end
		end		
	end
	
end
	

Next.MouseButton1Click:Connect(function()
	
	if currentitem > 6 then currentitem = 1
	else currentitem += 1 end
	ShowItem()
	
end)

previous.MouseButton1Click:Connect(function()
	
	if currentitem < 1 then currentitem = 6
	else currentitem -= 1 end
	ShowItem()
	
end)
1 Like

Tysm!!! This works! I’ve been wondering for so long.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.