Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
0
couldn't you use if Humanoid.HumanoidStateType == Enum.HumanoidStateType.Jumping then? creeperhunter76 554 — 6y
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. Sergiomontani10 236 — 6y
Ad

Answer this question