Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why does test1 print after test2 and test3?

script.Parent.OnServerEvent:Connect(function(plr)
	local slots = plr.Loadout
	local gui = plr.PlayerGui.Loadout
	local cur = plr.Character.TCount
	local p = slots:FindFirstChild("Slot"..tostring(cur.Value)) 
	local p2 = gui:FindFirstChild("Slot"..tostring(cur.Value)) 
	local d = plr.Places:GetChildren()
	local place = script.Parent.Parent.Parent.Parent.Parent
	local the = true
	for i=1, #d do
		if (d[i].Name == place.Name) then
			if (d[i].Value == true) then
				local l = slots:GetChildren()
				for q=1, #l do
					if (l[q].Value ~= place.Name) and p.Value == "" then
						p.Value = place.Name;
						local image = place.Image
						local idle = "rbxassetid://8322643381"
						p2.Cost.Value = place.GamePrice.Value
						p2.Info.Text =  place.GamePrice.Value;
						p2.Image = image;
						p2.Click.Idle.AnimationId = idle
						local n = plr.Character:GetChildren()
						for j=1, #n do
							if (n[j].Name == p2.Name) then
								n[j].Script.Idle.AnimationId = idle
							end
						end
						place.InfoFrame.MainButton.Text = "UNEQUIP"
						if the == true then
							the = false
							cur.Value = cur.Value + 1
							print("test1")
							break
						end
					elseif slots.Slot1.Value == place.Name or slots.Slot2.Value == place.Name or slots.Slot3.Value == place.Name or slots.Slot4.Value == place.Name then
						print("test2")
						local g = slots:GetChildren()
						for f=1, #g do 
							local s = gui:GetChildren()
							for z=1, #s do 
								if (g[f].Value == place.Name) then
									if (s[z].Name == g[f].Name) then
										print("test3")
										s[z].Image = ""
										s[z].Info.Text = "-"
										place.InfoFrame.MainButton.Text = "EQUIP"
										cur.Value = 1
										g[f].Value = ""
									end
								end
							end
						end
					end
				end
			end
		end
	end
end)

so when clicking the button the first time it works normally, but when clicking it the second time it prints test 2 and 3 then at the end it prints test 1, and i dont want it to print test 1, is there any reason why its doing this? https://imgur.com/a/qe1Av8A

1 answer

The 'elseif' statement is the one the script is following, then it is going to the 'if' statement afterwards, as something not there before has now got there. This is only a guess, and I'm not sure if I am correct. Not really dealt with this before. It seems like a logical answer, so do with it what you wish.

This discussion is preserved as it was. New answers, comments, and votes are closed.