Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I get get a NPC to jump when it touches a part but not when it touches a part in a player?

Currently, I'm in the process of designing a NPC that I'm going to use for one of my games. However, this script isn't working the way I'd like it to. How ideas on how I could fix it? The whole point of the script is to make my NPC jump when it touches a part but not when it touches the part of a Player.



function onTouched(part)
	if part.Name ~= {"Torso","Left Arm","Right Arm","Left Leg","Right Leg","Head"} then 
	script.Parent.Parent.Zombie.Jump = false
	if else

	script.Parent.Parent.Zombie.Jump = true	
	
	end
	
	
	end
end

script.Parent.Touched:connect(onTouched) 


4 comments

0

Here try this:                                                                                                                          function onTouched(part)02  local Humanoid = part:FindFirstChild("Humanoid") if Humanoid == nil then03    script.Parent.Parent.Zombie.Jump = false04    if else05 06    script.Parent.Parent.Zombie.Jump = true07 08    end09 10 11    end12end13 14script.Parent.Touche

1

Remove the extra "if" next to else and remove an "end"

0

Thanks, I'll try that.

0

I tried both suggestions and still didn't have any success :'(

1 answer

Try this;


local zombo = script.Parent.Parent:WaitForChild("Zombie") --Change this to the NPC 

zombo.Touched:Connect(function(Hit)
	if Hit.Parent.Name ~= {"Torso","Left Arm","Right Arm","Left Leg","Right Leg","Head"} then
		zombo.Jump = false
	else
		zombo.Jump = true
	end
end)

This should work, if it helped please accept answer.

1 comment

0

I copy and pasted that into a script and placed that inside the zombie's torso and it now it's not jumping at all. Maybe I'm doing something wrong?

This discussion is preserved as it was. New answers, comments, and votes are closed.