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 - 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.
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)
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!