My arrow script isn't working

I tried to make an arrow script, that has an if statement. It checks if you have a folder with standsummon, and if you do it’ll do nothing. But if you don’t have a folder, with standsummon, then it’ll give you a folder of that sort. It doesn’t work. Even if the player has a folder of the sort, then it’ll still give you a stand. I don’t know how to fix it.

--// Arrow Script

local rp = game:GetService("ReplicatedStorage")
local  Arrow = rp:WaitForChild("arrow")


Arrow.OnServerEvent:Connect(function(player, Arrow)
	wait(1.5)

	local Backpack = player:FindFirstChild("Backpack")

	local randomStand = math.random(1,3) --1 to the number of stands you have

	if Backpack then
		if randomStand == 1 then
			local Stands = game:GetService("ServerStorage"):WaitForChild("Stands")

			--//If stand is summoned
			local prevStand = workspace:FindFirstChild(player.Name.." Stand")
			if prevStand then
				prevStand:Destroy()
end
	
			for i, v in pairs(Backpack:GetChildren()) do
				if v:IsA("Folder") then
					local StandSummon = v:FindFirstChild("StandSummon")
					if StandSummon then
						print("Has Stand")
					
					
					elseif StandSummon == nil then
						local Stand = Stands:FindFirstChild("Stand1"):Clone()
						Stand.Parent = Backpack
  						local PlrStats = player:FindFirstChild("PlrStats")
						if PlrStats then
							local  currentStand = PlrStats:FindFirstChild("Stand")
							currentStand.Value = "Stand1"
						end									
					end
				end
			end

		elseif randomStand == 2 then
			local Stands = game:GetService("ServerStorage"):WaitForChild("Stands")

			--//If stand is summoned
			local prevStand = workspace:FindFirstChild(player.Name.." Stand")
			if prevStand then
				prevStand:Destroy()
			end

			for i, v in pairs(Backpack:GetChildren()) do
				if v:IsA("Folder") then
					local StandSummon = v:FindFirstChild("StandSummon")
					if StandSummon then
						print("Has Stand")
						

					elseif StandSummon == nil then
						local Stand = Stands:FindFirstChild("Stand2"):Clone()
						Stand.Parent = Backpack
						local PlrStats = player:FindFirstChild("PlrStats")
						if PlrStats then
							local  currentStand = PlrStats:FindFirstChild("Stand")
							currentStand.Value = "Stand2"
						end									
					end
				end
			end

		

		elseif randomStand == 3 then
			local Stands = game:GetService("ServerStorage"):WaitForChild("Stands")

			--//If stand is summoned
			local prevStand = workspace:FindFirstChild(player.Name.." Stand")
			if prevStand then
				prevStand:Destroy()
			end

			for i, v in pairs(Backpack:GetChildren()) do
				if v:IsA("Folder") then
					local StandSummon = v:FindFirstChild("StandSummon")
					if StandSummon ~= nil then
						print("Has Stand")
						

					elseif StandSummon == nil then
						local Stand = Stands:FindFirstChild("Stand3"):Clone()
						Stand.Parent = Backpack
						local PlrStats = player:FindFirstChild("PlrStats")
						if PlrStats then
							local  currentStand = PlrStats:FindFirstChild("Stand")
							currentStand.Value = "Stand3"
						end									
					end
				end
			end

		
			
	


			
			

		end
	end
end)

Could you please provide the script?

1 Like

oh ye. Sorry forgot about that. Done it.

1 Like

Is it possible that the script is running before the folder is added?

It may, I honestly don’t know.

the parts where you check the stand are too hacky

if randomStand == 1 then
			local Stands = game:GetService("ServerStorage"):WaitForChild("Stands")

			--//If stand is summoned
			local prevStand = workspace:FindFirstChild(player.Name.." Stand")
			if prevStand then
				prevStand:Destroy()
end
	
			for i, v in pairs(Backpack:GetChildren()) do
				if v:IsA("Folder") then
					if v:FindFirstChild("StandSummon") then
						print("Has Stand")
					
					
					else-- you can simply use else
						local Stand = Stands:FindFirstChild("Stand1"):Clone()
						Stand.Parent = Backpack
  						local PlrStats = player:FindFirstChild("PlrStats")
						if PlrStats then
							local  currentStand = PlrStats:FindFirstChild("Stand")
							currentStand.Value = "Stand1"
						end									
					end
				end
			end

Ok, I’ve tried with out the else if, still doesn’t work right.

Does anything insert “StandSummon” into v?

No, It inserts a new folder with StandSummon into the player’s backpack, if they don’t already have one.

There’s a different tool, that deletes that folder if you wish.

then you shouldnt be checking the children, you should be checking the name

if v.IsA("Folder") then
if v.Name == "StandSummon" then
--script
else

I should, because v is the folder, which contains StandSummon.

I’m trying to find, if they have a folder, which contains StandSummon, and if they don’t it’ll give them one.

for i,v in pairs (Backpack:GetChildren()) do
 if v:IsA("Folder") then
  if v:FindFirstChild("StandSummon") then

  print ("Has Stand")

else

 print("Doesn't have stand")

end
end
end
1 Like

No, it still doesn’t work. The problem is still persisting. It still gives me a folder, even if I already have a folder.

what Instance of class is StandSummon

StandSummon, is a local script contained within the folder, that allows you to summon your stand. I used this for checking, as the only folder that should have this, is the folder with the stand.

just try this raw, no edits, see if it prints

for i,v in pairs (Backpack:GetChildren()) do
 if v:IsA("Folder") and v:FindFirstChild("StandSummon") == nil then
 
  print (" doesnt Has Stand")

end
end

Ok. I’ve tested, it prints doesn’t has stand.

ok that’s good, try this one

for i,v in pairs (Backpack:GetChildren()) do
 if v:IsA("Folder") and v:FindFirstChild("StandSummon") == nil then
 
  print (" doesnt Has Stand")
 
elseif v:IsA("Folder") and v:FindFirstChild("StandSummon") == true then
print ("Has Stand")

end
end