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

Can someone give me an example of "Touchended" event. (?)

Asked by 4 years ago

Okay I would first of all like to say that I'm gonna be asking a lot of questions since I'm new to scripting and I'm very intrigued by lua.

So can someone give me a brief example of the Touchended event.

3 answers

Log in to vote
0
Answered by 4 years ago

A bit of an odd question but basePart:TouchEnded() fires whenever the part stops touching another part, it's rarely useful but on occasion can be used as a replacement for a constantly running loop.

For example, let's say I had made a king of the hill game and your teams score would only go up if someone on your team was on the hill. I could use a constant loop such as a while loop checking that the character is still touching the part. However, this wouldn't be ideal as it could slow down some devices. I would have a variable let's say team1Touching. When a player on team 1 touches the part (basePart:Touched()), team1Touching would be set to true. When TouchEnded() fires, the variable would then be set to false and the score would stop incrementing.

0
Ohh okay thank you! menofmen1234 20 — 4y
Ad
Log in to vote
0
Answered by
VitroxVox 884 Moderation Voter
4 years ago

Well touchended is mostly used when a user is touching an object and you want to execute a script/event when the user doesn't touch the box,object,part anymore

Example:

game.workspace.part.Touchended:Connect(function()
    print("he's not touching the part anymore")
end)
Log in to vote
0
Answered by 4 years ago

A touchended script is pretty much just the opposite of on touch. When you get off the specific part, you can run a certain script. For example,

function Touch()
     workspace.part.transparency=0.5
end

script.parent.TouchEnded:connect(TouchEnded)

That will change any part you like's transparency to 0.5. You can also change the brick color, shape, reflectance, etc.

0
I'm sorry for the late reply but I did figure out everything, but your explanation is... not so good, You are making the function do the transparency = 0.5.... But you don't actually give the Touch:connect function first, so it makes TouchEnded act like it's a Touched:Connect Function... And you are calling a function that doesn't exist... script.parent.TouchedEnded:connect(TouchEnded??) menofmen1234 20 — 4y

Answer this question