Need help on Killer not moving

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)

Are there any errors on the Output?

No there isn’t any errors, the only text coming out of the script is the prints

I think it’s probably cause sound.IsPlaying == true can’t be writen from as a check argument? Maybe you can try doing:

while true and sound.Playing == true do

You can also check these 2 API References:

Wouldn’t really make sense if it worked, and It didn’t; Maybe somethings overwriting the script?

Maybe, could you also check to see if the sound variable is an actual Sound Instance? And that the Killer’s WalkSpeed is not at 0 lol

Yeah, I tried as well the opposite of playing, i did paused and set it to false and it still didnt work-

Hm, could you send the place as a RBMX (Or RBMX WHATEVER IT IS) file so I could see it? That’s very strange

It’s a project so I don’t feel comfortable sharing it.

Hank - Roblox there you go

My guess is that its only checking if Sound.IsPlaying is true once and since its false, it won’t loop again:

while true and sound.IsPlaying == true do

What I suggest you try is the same thing except create an if statement like so:

while wait(1) do
	local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
	if target ~= nil and sound.IsPlaying == true then -- Not sure why you checked sound.IsPlaying in the while loop and here? No need to check it twice!
		script.Parent.HANK:MoveTo(target.Position, target)
	end
end;

I’m on mobile so there may be typos!

If the above isn’t the case than could you put a couple of prints within your loop. One to make sure the loop is running, one after you define target (just print target to see if its nil) and one after the if statement!

Hopefully this helps!

OK SO, after doing some configuration I think I found what the issue is here! So let’s refer back to this script right here:

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

The reason why this loop does not work, is because it’s checking to see if the loop has met the correct requirements or not, it if DOESN’T, then the script just continues through it’s script, instantly ignoring that loop. To fix this, we can insert this:

while true do
	wait(1)
    if sound.IsPlaying == true then
	    local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
	    if target ~= nil and sound.IsPlaying == true then
		    script.Parent.HANK:MoveTo(target.Position, target)	
        end
	end
end

So the script is doing a wait(1) loop, and checking to see if the sound variable is played or not. If it is, then we can set the Humanoid to move to the closest target!

Another thing that I’ve noticed in your Activate Touch Script:

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(2)
		hank:Clone()
		whisperign:Stop()
		game.Lighting.FogEnd = 100
		debounce = true
	else
		debounce = true
	end 
end
script.Parent.Touched:connect(onTouched)

You’re trying to destroy & clone the same Variable, and I’m pretty sure you can’t do that :thinking: To easily avoid this mistake, you can clone another Hank in the ReplicatedStorage and do this instead:

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(2)
		local hank = game.ReplicatedStorage.Hank:Clone()
		hank.Parent = workspace
		hank:MakeJoints()
		whisperign:Stop()
		game.Lighting.FogEnd = 100
		debounce = true
	else
		debounce = true
	end 
end
script.Parent.Touched:connect(onTouched)

This will create an entirely new Hank, which will activate! Hope this helps!

Yes I realized that mistaked earlier, and it still didn’t work; your explanation might be right but it isn’t the problem

I just got on pc and managed to get it to work. The issue did have to do with you having the condition in the while line. Also as @JackscarIitt mentioned you are destroying “hank” the second anyone touches the brick.

Read jacks response as he nailed the issue!

Oh that hank was a decal, I wanted to add decoration as to when you get close to fake hank he disappears and you get chased, I wanted to make it when the debounce cooldown is over he comes back to the place where he was, but I didn’t get it to work, I think it teleports the clone to another position

Really clear explanation, Thank you a lot!

1 Like

HankThingy.rbxm (12.8 KB)

Oh yeah btw, here’s the updated thing Honestly seeing Hank Hill bribing me to buy his propane tanks in the fog is scary ngl LOL

Haha yea I agree, but here is the fixed version I made, yours worked perfectly fine but he stayed on attack mode forever, pretty simple fix

while true do
	wait(1)
	if sound.IsPlaying == true then
		local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
		if target ~= nil and sound.IsPlaying == true then
			script.Parent.HANK:MoveTo(target.Position, target)	
		elseif
			target ~= nil and sound.IsPaused == true then
			return nil
		end
	end
end

Thanks a lot! :smiley:

1 Like