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

How do you make it that when you touch a brick while jumping you take damage?

function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h~=nil then
h.Health = h.Health -20
wait(2.00)
end
end

script.Parent.Touched:connect(onTouched)

So far I cant find out how to make it that you take damage while your jumping instead of having it where you take damage while your just walking which would be unrealistic in a game Im developing for but not doing much scripting unless my friend needs it. Can't figure it out any suggestions?

1 answer

✓ Accepted answer

Well, there is a bool inside of Humanoid called "jumping" also use :Connect not :connect because :connect was deprecated and now :Connect effectively has taken its place.

so do like this:

function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
		if h~=nil and h.Health > 0 and h.Jumping == true then
		h.Health = h.Health -20
		wait(2)
	end
end

script.Parent.Touched:connect(onTouched)

also i suggest debugs so they don't basically instantly die

example:

bool = true

function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
		if h~=nil and h.Health > 0 and h.Jumping == true and bool = true then
		wait()
		bool = false
		h.Health = h.Health -20
		wait(2)
		bool = true
	end
end

script.Parent.Touched:connect(onTouched)

2 comments

0

couldn't you use if Humanoid.HumanoidStateType == Enum.HumanoidStateType.Jumping then?

0

It didn't end up working, still tryna find the solution although I knew it a lil with older roblox code. gg roblox updates gg.

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