#Help about paremeeters and events

1 messages · Page 1 of 1 (latest)

violet karma
#

Im tryna learn scripting from Roblox docs but im at this
local trap = script.Parent

local function onTouch(objectTouched)
print("Something touched the trap")
end

-- Connect the function to the Touched event
trap.Touched:Connect(onTouch)
And im learning parameters and events but i do not understand why local function and why trap.tuched:connect(onTuch)

violet karma
vernal shell
worthy lion
# violet karma Im tryna learn scripting from Roblox docs but im at this local trap = script.Pa...

So I like to think of local as defining what this (in this case trap) is for this specific script. So in this scenario
Local trap = script.parent means that in this script when you use the phrase "trap" and whatever other code after it. The script knows you are talking about the part this script is in. Or the "Parent" of the script

So with trap.touched:connect(onTouch)
It's saying, "Hey. If the parent of this script (trap) gets touched by something then do this function (ontouch)" .

Just my own little explanation of it. Not entirely helpful and may be wrong in some places, thats on me so take it with a grain or two of salt . but it's my way of understanding local and allat jazz so I thought I'd share

violet karma
worthy lion
#

It also comes naturally so don't sweat it. The more you play with these different codes the more you get to know em better ^_^

violet karma
#

Thanks man also idk but i tried learning from tutorials before and did not go the best each episode was like 30+ min and i got bored so im learning from Roblox documents and i already learned alot more but its harder to learn from there and more complex 🙂

worthy lion
violet karma
#

Yeah also one last thing and imma try figuring it out myself i forgot why do i write smth in the box after this

worthy lion
#

Like I just recently figured out how tween stuff works 😭

violet karma
#

😅 im just a qurious guy ig

worthy lion
#

When I look at functions like that I always considered that parentheses to be what contains the parameters. But it doesn't make sense there at least not to me so idrk. I think I'm in the same boat 😭

violet karma
#

I found it out

#

It was the name of the parameter they used it to destroy whatever touched it look

worthy lion
#

OHHH YEAH

sterile daggerBOT
#

studio** You are now Level 4! **studio

worthy lion
#

I use that for hitbox codes

violet karma
#

Yh i just found out its not a kill brick bcuz it doesnt set health to 0 but if my arm for example tuches it its gone

sterile daggerBOT
#

studio** You are now Level 9! **studio

worthy lion
#

Like hitbox.touched:connect(function(hit)

#

Crazy but it clicked

violet karma
# worthy lion Like hitbox.touched:connect(function(hit)

Ok so lemme try and explain this script of what i learned so far hitbox is probably something before in the script with local hitbox = ....
And .touched is when someone s tuches it and :connect is to connect the touched event with function hit but i dont understand function hit

worthy lion
#

Right I can share my code that might help you see the reason hit its there better

violet karma
#

Yeah

worthy lion
violet karma
#

Ok wth 😭😭

#

Im over stimulating

worthy lion
#

So this is the whole function train used for making your opponent go silly if you hit them

violet karma
#

Lol so it plays a animation when they are hit right

worthy lion
#

Yessir

violet karma
#

Ok thats probaly the i ly of the code i understood

#

I started to learn scripting yesterday lol but im at Parameters practice - buttons in Roblox docs so thats probaly gonna be fun

worthy lion
#

We need to generalize that back to character

#

So we do hit.parent

#

And THEN that's where we can get the humanoid and everything else we need for some awesome shenanigans

violet karma
#

Dont quite understsnd it still but i understand it better than before

worthy lion
#

Yes please don't pay any mind to the rest of that hocus pocus that's extra stuff just to get a sound and animation to play

violet karma
#

Rn in Roblox docs im learning to like make a button that turns green when stepped on and make a bridge collision=true i think so

worthy lion
#

Ooo that's a fun one

#

That uses tween service or doesn't and just uses script to make a instant change

violet karma
#

Yeah and hopefully of what ive learned il be able to add in a sound effect too for extra work to get better

worthy lion
#

Sound stuff is pretty easy to get down after you figure out the fundamentals I believe in ya lad

#

We don't talk abt roll off types and allat tho

#

Not even I know that yet

violet karma
#

Its maybe gonna be a little bit harder bcuz it starts with transparency 0.5 too and i havent tried changing 2 properties in 1 function or yk what i mean

worthy lion
#

If you wanna change multiple properties at once tween service might be the way to go.

#

Trust me it looks scary but once you get it you'll be soaring through it

#

Tweens can change any property you can think of on a part. Even position I believe

#

Like I have my name in my credits set to constantly change colors using tweens

violet karma
#

Oh my they gave me this bridge.CanCollide = true and told me to try and do the rest myself 😭😭

worthy lion
#

😭

#

Practice makes perfect ig loll

violet karma
#

But cant do right now im on a phone but what if i try and write it in here and u tell me if it looks right or not

worthy lion
#

Sure works for me ^_^ I got roblox studio open on my game rn anyways so I can run it through

#

You wanna try to jump the gun and try out tween service? If you get it down it'll make changing colors and sizes during a game a lot easier on ya

violet karma
#

Ok so this script is inside a brick thats works as the bridge

worthy lion
#

If not I understand either way I'll happily oblige

worthy lion
#

No fancy drawbridge or nothing just like a block between a gap right?

#

Trying to imagine it 😭

violet karma
#

Local bridge = script.parent

Local function onTuch(TuchedBridge)

#

Oh my im brain dead

#

I cant remember anymore 😭

#

Ooh my days it wasnt even supposed to go into the bridge it was supposed to go into the button

worthy lion
#

Also just sending this to ya for future reference I noted what stuff does in most of this

#

Most as in 1 third 😭

violet karma
#

Wait local button = script.parent
Local bridge = workspace.bridge
Local function

#

And thats all i remember

worthy lion
#

Hmmm seems right up to that point yeah

#

Remember to connect the function when the button is touched

vernal shell
worthy lion
#

And since you wanna make it to where the bridge can collide so you can walk across you can do something like this

Local Bridge = workspace.bridge
Local button = script.parent

Local function(OnTouch)
Bridge.CanCollide = true
)
button.touched:Connect(OnTouch)

I think I'm not too sure

worthy lion
worthy lion
#

I forgot I have tables to figure out 😭 I got locked in on the side quest