I asked this in an earlier post but i closed it because i had to go for a long time, my issue is this:
The player should jump from one part to the other, however, they just keep going to the first part
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,10,0)
wait(0.3)
BPos.Position = closest[1].Position + Vector3.new(0,50,0)
wait(0.3)
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)
It only switches targets when the player touches the floor. which is what i don’t want to happen because it’s going to be on pillars and it won’t be possible that way then.
any way to solve this?