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

How do i make an NPC humanoid jump when player humanoid jumps?

I have an NPC for a game and i want to make it so every time the player jumps, the NPC would jump too. I may of made a simple mistake but i don't know why it won't detect the player in workspace.

if game.Workspace.Player.Humanoid.Jump == true then
	script.Parent.Zombie.Jump = true --Zombie is the name of the NPC's humanoid.
end

Any help? Thanks.

1 comment

0

The way you do it right now would only work in studio, but you'd need "Player1" instead. Suggest to make the zombie jump whenever it hasnt changed position (Magnitude check < 1) in 5 secconds

1 answer

✓ Accepted answer

It would be best to use the Jumping event of the players humanoid.

Example code:-

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(charModel)
		local humanoid = charModel:WaitForChild('Humanoid')
		if humanoid then
			humanoid.Jumping:Connect(function(jmp)
				-- code here
			end)
		end
	end
end)

This is just an example there are different ways of doing this but you will need to find the best solution for your needs.

I hope this helps.

3 comments

0

This did help, thanks so much.

0

Just one question, how could I make it if a nearby humanoid jumps then it would run the code?

0

This would probably need to manage this from the player side, when they jump look for the closest NPC and make it jump. But I do not know how you game is designed / intended to work.

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