"For" loop is not checking for already equipped tools

Hello. I’m trying to make this GUI where it gives you a ticket. The way it suppose to work is that when you open it again and you already have a ticket, it’s supposed to say so. Here’s what I provided in a local script:

local button = script.Parent.TextButton

local regularText = "Welcome!"

local OkButton = script.Parent.OkButton
OkButton.Visible = false

local ticketReceived = game.ReplicatedStorage["Check-In Events"]:WaitForChild("AmericanCheck-In")

local ticket1 = game.ReplicatedStorage.Tickets["Economy Ticket"]
local ticket2 = game.ReplicatedStorage.Tickets["Club Ticket"]
local ticket3 = game.ReplicatedStorage.Tickets["First Class Ticket"]

local class1 = script.Parent["Seating Classes1"]
local class2 = script.Parent["Seating Classes2"]
local class3 = script.Parent["Seating Classes3"]

local freeButton = script.Parent.Free
local groupButton = script.Parent.Group
local passButton = script.Parent.Pass

local thingsToSay = {"Have a nice flight!"; "Enjoy your trip!"; "Safe travels!"}

local buttons = {class1, class2, class3, freeButton, groupButton, passButton}

local gamepassID = 44128567
local mps = game:GetService("MarketplaceService")

for i, v in pairs(buttons) do
	v.Visible = false
end

button.MouseButton1Click:Connect(function()
	button.Visible = false
	script.Parent.TextLabel:TweenSize(UDim2.new(0, 400, 0, 45), 0.75)
	wait(0.75)
	for i, v in pairs(buttons) do
		v.Visible = true
	end
end)

local player = game.Players.LocalPlayer



local ticketEquipped = {player.Backpack:FindFirstChild("Economy Ticket");
	player.Backpack:FindFirstChild("Club Ticket");
	player.Backpack:FindFirstChild("First Class Ticket")
}

freeButton.MouseButton1Click:Connect(function()
	ticket1:Clone().Parent = player:WaitForChild("Backpack")
	for i, v in pairs(buttons) do
		v.Visible = false
	end
	script.Parent.TextLabel.Text = "You have received your ticket. "..thingsToSay[math.random(1, #thingsToSay)]
	OkButton.Visible = true
	
	ticketReceived:FireServer(player, ticket1)
end)

groupButton.MouseButton1Click:Connect(function()
	
	if player:IsInGroup(12749630) then
		ticket2:Clone().Parent = player:WaitForChild("Backpack")
		for i, v in pairs(buttons) do
			v.Visible = false
		end
		script.Parent.TextLabel.Text = "You have received your ticket. "..math.random(1, #thingsToSay)
		OkButton.Visible = true
	else
		script.Parent.TextLabel.Text = "Sorry, you need to join the group to access this."
		OkButton.Visible = true
		for i, v in pairs(buttons) do
			v.Visible = false
		end
	end
	
	ticketReceived:FireServer(player, ticket2)
end)

passButton.MouseButton1Click:Connect(function()
	if mps:UserOwnsGamePassAsync(player.UserId, gamepassID) then
		
		ticket3:Clone().Parent = player:WaitForChild("Backpack")
		for i, v in pairs(buttons) do
			v.Visible = false
		end
		script.Parent.TextLabel.Text = "You have received your ticket. "..math.random(1, #thingsToSay)
		OkButton.Visible = true
		
		ticketReceived:FireServer(player, ticket3, mps, gamepassID)
		
	else
		
		for i, v in pairs(buttons) do
			v.Visible = false
		end
		
		script.Parent.TextLabel.Text = "Sorry, you must require a gamepass to buy this ticket!"
		OkButton.Visible = true
		
		return mps:PromptGamePassPurchase(player, gamepassID)
	
	end
end)

OkButton.MouseButton1Click:Connect(function()
	script.Parent.Visible = false
	OkButton.Visible = false
	
end)

workspace["Check-In Desk 1"].Union1["Check-In"].Triggered:Connect(function()
	
	script.Parent.Visible = true
	script.Parent.TextLabel.Size = UDim2.new(0, 400, 0, 100)
	
	for _, alreadyOwned in pairs(ticketEquipped) do
		
		if alreadyOwned then
			script.Parent.TextLabel.Text = "You already have a ticket!"
			button.Visible = false
			OkButton.Visible = true
		else
			script.Parent.TextLabel.Text = regularText
			button.Visible = true
			OkButton.Visible = false 
		end
		
	end
	
end)

workspace["Check-In Desk 1"].Union2["Check-In"].Triggered:Connect(function()
	
	script.Parent.Visible = true
	script.Parent.TextLabel.Size = UDim2.new(0, 400, 0, 100)
	
	for _, alreadyOwned in pairs(ticketEquipped) do
		
		if alreadyOwned then
			script.Parent.TextLabel.Text = "You already have a ticket!"
			button.Visible = false
			OkButton.Visible = true
		else
			script.Parent.TextLabel.Text = regularText
			button.Visible = true
			OkButton.Visible = false
		end
		
	end
	
end)

This is where the ticket already equipped reminder should function:

workspace["Check-In Desk 1"].Union1["Check-In"].Triggered:Connect(function()
	
	script.Parent.Visible = true
	script.Parent.TextLabel.Size = UDim2.new(0, 400, 0, 100)
	
	for _, alreadyOwned in pairs(ticketEquipped) do
		
		if alreadyOwned then
			script.Parent.TextLabel.Text = "You already have a ticket!"
			button.Visible = false
			OkButton.Visible = true
		else
			script.Parent.TextLabel.Text = regularText
			button.Visible = true
			OkButton.Visible = false 
		end
		
	end
	
end)

But this is the result I’m getting…

…when it’s supposed to say, “You already have a ticket!” and the OK button should pop-up with it. It would be appreciating for you to come up with a way to solve this.

This is only done once at the start which presumably means you end up with an empty table initially. You don’t seem to update this list as far as I can see so the for loop wouldn’t end up actually doing anything.

1 Like

if it’s equipped, its moved from the backpack to your character in the workspace.

1 Like

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