How would i exclude a part from a table that selects it?

This should be the final time i show this script because this is the last issue.

UIS = game:GetService("UserInputService")
Plr = game.Players.LocalPlayer

Plr.CharacterAdded:Connect(function()
	local Char = Plr.Character
	local Hum = Char:WaitForChild("Humanoid")
	local HumRP = Char:WaitForChild("HumanoidRootPart")
	local HS = Hum:GetState()
	local Targs = workspace.JumpTargets:GetChildren()
	local Connection
	Hum.StateChanged:Connect(function()
		HS = Hum:GetState()
		if HS == Enum.HumanoidStateType.Freefall then
			local partsTable = Targs
			local closest = {nil,50}
			for i,v in pairs(partsTable) do
				if v:IsA("BasePart") then
				local distance = (HumRP.Position - v.Position).magnitude
				if distance < closest[2] then
					closest = {v, distance}
					print(closest)
					end
				end
			end	
			local CD2 = false
			local CD1 = false
			if closest[2] < 30 then
				print("Within range")
				if CD1 == false then
					CD1 = true
					if Connection then Connection:Disconnect() end
					Connection = UIS.InputBegan:Connect(function(Key)
						Key = Key.KeyCode
						if Key == Enum.KeyCode.Space then
							if HS == Enum.HumanoidStateType.Freefall then
								if not closest[1]:FindFirstChild("BillboardGui") then
									local RealTarg = script.BillboardGui:Clone()
									RealTarg.Parent = closest[1]
									script["Lock On"]:Play()
									if CD2 == false then
										CD2 = true
										local BPos = Instance.new("BodyPosition")

										BPos.Parent = HumRP
										BPos.MaxForce = Vector3.new(55000,55000,55000)
										BPos.P = 55000
										BPos.Position = closest[1].Position + Vector3.new(0,4,0)
										wait(0.3)
										BPos.Position = closest[1].Position + Vector3.new(0,15,0)
										
										wait(0.1)
									closest[1].Parent = workspace.JumpTargets.Used
									BPos:Destroy()
									RealTarg:Destroy()
									CD2 = false
									end
								end
							end
						end
					end)
				else
					print("No nearby targets found")
					if Connection then Connection:Disconnect() end
				end
			else
				if Connection then Connection:Disconnect() end
			end
		else
			if Connection then Connection:Disconnect() end
		end
	end)
end)

The issue is that i don’t know how to exclude a part from a table. let me elaborate;

When the player jumps, a table is printed showing the closest part to the player. when the player is sent to that part, i want the part to not be seen by the table for a set amount of time, this allows the player to jump to the next one instead of getting stuck in the first one, how would i go on about doing this?

1 Like

I’d probably just modify this line.
if distance < closest[2] and v ~= partToExclude then

ill need to include it back after some time though, how would i do that? it’s basically a cooldown but debounce won’t work in this scenario

How do you mean? I assuming this is some sort of wall grab system. You want to re-enable grabbing the same wall while they’re still on it?

okay what i mean is:

1 - player is sent to part
2 - part is removed from table so player can no longer get sent to it
3 - player moves to next part
4 - during the time the player moves to the next part, the old part is back in the table

As a note: i tried removing them from the table but their position still saves

Does my fix not do that? PartToExclude is just the part they’re currently on. Once they move to the next part, set PartToExclude to the new part that they just grabbed.

i don’t think i read it correctly now that i look at it again, sorry. i’ll try it and see if it works

Just tried it out, Nothing changed compared to the last result https://gyazo.com/5a4819dad46de10c33b9a4f7d37130ee

Where are you setting PartToExclude at?

Closest[1] which is the closest part

You need to set it to be the part he has currently teleported to. You’ll need to mess around with where you reset PartToExclude to nil.

UIS = game:GetService("UserInputService")
Plr = game.Players.LocalPlayer

Plr.CharacterAdded:Connect(function()
	local Char = Plr.Character
	local Hum = Char:WaitForChild("Humanoid")
	local HumRP = Char:WaitForChild("HumanoidRootPart")
	local HS = Hum:GetState()
	local Targs = workspace.JumpTargets:GetChildren()
	local Connection
    local PartToExclude
	Hum.StateChanged:Connect(function()
		HS = Hum:GetState()
		if HS == Enum.HumanoidStateType.Freefall then
			local partsTable = Targs
			local closest = {nil,50}
			for i,v in pairs(partsTable) do
				if v:IsA("BasePart") then
				local distance = (HumRP.Position - v.Position).magnitude
				if distance < closest[2] and v ~= PartToExclude then
					closest = {v, distance}
					print(closest)
					end
				end
			end	
			local CD2 = false
			local CD1 = false
			if closest[2] < 30 then
				print("Within range")
				if CD1 == false then
					CD1 = true
					if Connection then Connection:Disconnect() end
					Connection = UIS.InputBegan:Connect(function(Key)
						Key = Key.KeyCode
						if Key == Enum.KeyCode.Space then
							if HS == Enum.HumanoidStateType.Freefall then
								if not closest[1]:FindFirstChild("BillboardGui") then
									local RealTarg = script.BillboardGui:Clone()
									RealTarg.Parent = closest[1]
									script["Lock On"]:Play()
									if CD2 == false then
										CD2 = true
										local BPos = Instance.new("BodyPosition")

										BPos.Parent = HumRP
										BPos.MaxForce = Vector3.new(55000,55000,55000)
										BPos.P = 55000
										BPos.Position = closest[1].Position + Vector3.new(0,4,0)
										wait(0.3)
										BPos.Position = closest[1].Position + Vector3.new(0,15,0)
										
										wait(0.1)
									closest[1].Parent = workspace.JumpTargets.Used
                                        PartToExclude = closest[1]
									BPos:Destroy()
									RealTarg:Destroy()
									CD2 = false
									end
								end
							end
						end
					end)
				else
                    PartToExclude = nil -- this one might be extra
					print("No nearby targets found")
					if Connection then Connection:Disconnect() end
				end
			else
                PartToExclude = nil
				if Connection then Connection:Disconnect() end
			end
		else
			if Connection then Connection:Disconnect() end
		end
	end)
end)
1 Like

will try this, i’ll be back if it works / doesn’t work

i think this improved it (player doesn’t go to the first one constantly AS MUCH), but the player still goes to the first one constantly

i gtg so i’ll make your script the solution because it’s the closest thing to what i wanted to achieve, i think i can figure out the rest when i get back. thank you! :slightly_smiling_face: