#how can i count the amount of times the touched event has been fired

1 messages · Page 1 of 1 (latest)

exotic cloak
#

i just want to create a function that keeps track of how many times a part has been touched

rose sage
#
local counter = 0;

part.Touched:Connect(function(hit)
    counter += 1;
end)

exotic cloak
#

um

#

so i have questions to do with how that works

#

because i also want to understand it

#

for lua local counter = 0; what does the semi colon do

#

and also what does hit do

sleek frost
#

nothing

#

it does nothing

#

just a habit when you use other languages other than roblox lua

exotic cloak
#

oh

#

and what about hit

#

ive seen it used in other scripts but idk what it does

#

oh yh and what does that += symbol mean togethor

sleek frost
#

hit is the part which the main part has touched

sleek frost
#

basically a simplified version of x = x + 1

exotic cloak
exotic cloak
sleek frost
exotic cloak
#

is hit an event?

sleek frost
#

No.

exotic cloak
#

eh

sleek frost
#

That's what is being return.

#

Hit is just a variable.

exotic cloak
#

so hit just means when to parts touch eachother?

sleek frost
#

hit is PartB. So yes.

exotic cloak
#

idk if i understand it properly

#

cos in that way it sounds a lot like an event

#

where can i read abuot it

sleek frost
#

Touched is the event.

exotic cloak
#

yuh

#

but what does hit do

#

by definition

#

i wanna know what hit is

sleek frost
#

hit is PartB. hit is the part PartA has made contact with.

exotic cloak
#

oh ok

#

so when a players character walks into a part

#

and they have touched it

#

which one of them is hit

sleek frost
#

Any part.

#

Any parts in the class of BasePart.

#

It can be a union, wedge, part, meshpart.

exotic cloak
#

so it can never be a player?

sleek frost
#

It can't be anything other than a part.

#

So yes.

#

It would not return the instance of player.

exotic cloak
#

a players character i mean

sleek frost
#

No.

exotic cloak
#

like their arm

sleek frost
#

A player's character is a model and not a basepart.

exotic cloak
#

oh ok

sleek frost
exotic cloak
#

eh.

#

damn

#

uh

#

ig what im tryingg to ask is

#

if im playing the game

#

and i talk into a block

#

which is a base part

#

am i able to be "hit"

sleek frost
#

The BasePart would be any part that has touched PartA.

exotic cloak
#

wht do u mean by part A

sleek frost
#

PartA is referred as the part with the touched event.

#

e.g. workspace.RandomPart.Touched

#

That would be PartA

exotic cloak
#

oh ok

#

ohhhhh ok i think i get it now

#

so if i say ```lua
local part = workspace.part

part.touched:connect(function
-- code
end)```

#

the part is touch A ?

#

i mean.

#

the part is partA?

#

and what ever just touched it is partB

sleek frost
#

Yes, Correct.

exotic cloak
#

alrrrr so my players character is hit then ?

#

not their character

#

but what ever part of their avatar just hit the part

rose sage
#

@exotic cloak focus on actually programming and not getting the newest syntax correct

#

syntax can be learned but not universally applied.

#

fundamental programming can be universally applied.

exotic cloak
#

its a part of what im making

rose sage
#

long term ^^

exotic cloak
#

basically i want to make a win system

#

where the first 3 players to cross the finish line are put in order

#

on this like

#

eh idk wht to call it

#

platform

#

where the 1st winner is the hiest

#

highest*

#

so the idea i had was to count the amount of times its been touched

#

and then make a function that inerts a players character model

#

and it obiously depends on what ever count is equal to

exotic cloak