Wanting to understand how this trampoline script works

Hello there! Tommy here.
As you can see. I recently want to learn Roblox scripting. I decided to start learning with an easy script from Roblox studio Toolbox two days ago first. I dragged out a free model from it. It’s a trampoline!
https://gyazo.com/bccc00a3af96e002a145413e168addff
The creator of the trampoline is EndorsedModel
So, it worked like this.
And, the script looks like this:


script.Parent.Touched:connect(function(obj)
	local humanoid = obj.Parent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
	    humanoid.JumpPower = script.Parent.Parent.Configurations.JumpForce.Value
	    humanoid.Jump = true
	    wait(1)
	    humanoid.JumpPower = defaultJumpPower
	end
end)

I already searched the APIs meaning on DevHub.
But, I still can’t figure it out. :sweat_smile: Sorry
I planned to post only once this kind of post about scripting.
In the future, I might not be going to post like kind of this again.

Thanks for reading!

script.Parent.Touched:Connect(function(obj) -- This is a touched event, it fires when the part being defined was touched. The parameter "obj" is the object that touched this part.
	local humanoid = obj.Parent:FindFirstChildWhichIsA("Humanoid") -- Defining where the humanoid is. If The "obj" is a part in the character, then it's model will have a Humanoid in it.
	if humanoid then -- If we find a humanoid in obj.Parent then we know that a character touched this part instead of a random object.
	    humanoid.JumpPower = script.Parent.Parent.Configurations.JumpForce.Value -- Jumpower is a property of the Humanoid, it defines how high you can jump. You are setting the character's jump power to the value of a IntValue that is in a configuration's folder inside this model.
	    humanoid.Jump = true -- "Jump" is a property of the humanoid. If you set Jump to true, the character jumps.
	    wait(1) -- Waiting one second for the character to stop jumping.
	    humanoid.JumpPower = defaultJumpPower -- Setting the JumpPower to the value of a variable.
	end -- Ending the if statement
end) -- Ending the function

Here you go! If you need any more clarification, feel free to ask.

5 Likes

Oh also, I just noticed this… Make sure to always put a capital C in Connect, or it will result in an error.

2 Likes

Not actually true, connect works without capitals in some of my scripts

1 Like

I believe it works with a lowercase c, however last time I checked. It will put an error for not using a capital C.

1 Like

Almost all stuff like that works without a capital, Destroy() doesnt need one, clone and connect, but it is a better habit to use capitals so you are right

1 Like

Thank you so much for the explanation! I might going to ask some questions later thanks.

there are tutorials explaining about touched events not only on Devhub though

1 Like