local UIS = game:GetService("UserInputService")
local Plr = game.Players.LocalPlayer
local debounce = false
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()
Hum.StateChanged:Connect(function()
HS = Hum:GetState()
if HS == Enum.HumanoidStateType.Freefall then
local partsTable = Targs
local closest = {nil,30}
local CloPart
for i,v in pairs(partsTable) do
local distance = (HumRP.Position - v.Position).magnitude
if distance < closest[2] then
closest = {v, distance}
CloPart = v
end
end
if closest[2] < 30 then
print(closest[2])
UIS.InputBegan:Connect(function(Key)
Key = Key.KeyCode
if Key == Enum.KeyCode.Space then
if HS == Enum.HumanoidStateType.Freefall then
if debounce then
return
end
if closest[2] < 30 then
debounce = true
local RealTarg = game.ReplicatedStorage["PH1--Target"].BillboardGui:Clone()
RealTarg.Parent = closest[1]
script["Lock On"]:Play()
print(CloPart)
local chrPos=Char.PrimaryPart.Position
local tPos=CloPart.Position
local newCF=CFrame.new(chrPos,tPos)
Char:SetPrimaryPartCFrame(newCF)
Char.Torso.Anchored = true
task.wait(1)
RealTarg:Destroy()
Char.Torso.Anchored = false
debounce = false
end
else print("Not in range")
end
end
end)
else
task.wait(1)
end
end
end)
end)
when the player goes further than 30 studs away from the target(s) it still locks onto the closest one. when they leave the range then nothing should be happening… why is this happening?
the script does print that the plr is out of range but it still locks onto the parts
https://gyazo.com/e571f4a8ef80a8e5b9a61249e47f1486 – what is happening right now
(works fine until the player locks onto a part for the first time. after that, they can lock onto it from any range even though it’s meant to be <30.)
changing the range doesn’t work either…