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.
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.
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)
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.