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

How would I call a function only when two events are triggered?

Asked by
parkderp1 105
9 years ago

I want to play an animation only when the player jumps and is touching a part. How would I do that.

P.S. I have not been able to find anything on the wiki.

1
This is actually a very tricky question: How do you know if the player is touching a part? See this question for some ideas: https://scriptinghelpers.org/questions/13175/custom-characters-detecting-the-ground duckwit 1404 — 9y

1 answer

Log in to vote
1
Answered by
duckwit 1404 Moderation Voter
9 years ago

There is a simple, approximate solution to this and there are plentifully more complicated ones.

Just to clarify:

(1) You write that you want the animation to play when the player jumps "and is touching a part" - I interpret this to mean "and is on the ground"; the animation should only trigger if the player is supported by something (i.e. not falling).

(2) You aren't wanting to play an animation when two events are triggered; you want the animation to play when a certain, single event (Humanoid.Jumping) fires under specific circumstances (or conditions). The event, which happens in one tiny discrete unit of time, must happen whilst the condition 'Is the player on the ground?' is 'Yes' (true).

The ROBLOX client developers have spent a lot of time tweaking the behaviour of Player characters and the Humanoid - you can benefit from this. The Humanoid.Jumping event will only fire when the player can make a valid jump, which happens to be when the character is on the ground (which is the condition you want).

So, simply put, play your animation when the Humanoid.Jumping event fires.

0
By touching a part I was talking about an obstacle such as a building or something. I should've specified. parkderp1 105 — 9y
0
Although, the question you supplied does supply me with some interesting experiments for later on. parkderp1 105 — 9y
0
If you look at the answer I gave (to my own question, haha) about using the position of ROBLOX Parts to test for collisions, you could use a similar technique to detect if there is an obstacle in front of the player, perhaps. duckwit 1404 — 9y
0
That might work. parkderp1 105 — 9y
Ad

Answer this question