So, after I put in while true and sound.IsPlaying == true do It stopped working, I don’t understand why it isn’t moving anymore, what is supposed to happen is when a player steps on a block it plays a heartbeat sound and the killer follows the player
Here are the scripts,
Pathfinding Main
local p = script.Parent
local larm = script.Parent:FindFirstChild("HumanoidRootPart")
local rarm = script.Parent:FindFirstChild("HumanoidRootPart")
local sound =script.Parent.Parent.heartbeat
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 10000
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("HumanoidRootPart")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
p.HumanoidRootPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
local human = hit.Parent:FindFirstChild("Humanoid")
human:TakeDamage(100)
print(human.DisplayName.." Took Damage")
end
end)
–the line that broke the script ))):
while true and sound.IsPlaying == true do
wait(1)
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil and sound.IsPlaying == true then
script.Parent.HANK:MoveTo(target.Position, target)
end
end
OnTouch Script (Works Fine)
debounce = true
hank = script.Parent.Parent.Hank
heartbeat = workspace.heartbeat
whisperign = workspace.Whispering
function onTouched(hit)
if debounce == true and hit.Parent:FindFirstChild("Humanoid") ~= nil and not hit.Parent:FindFirstChild("Hank") then
debounce = false
wait(0)
heartbeat:Play()
whisperign:Play()
hank:Destroy()
game.Lighting.FogEnd = 50
wait(12)
hank:Clone()
whisperign:Stop()
game.Lighting.FogEnd = 100
debounce = true
else
debounce = true
end
end
script.Parent.Touched:connect(onTouched)