Beginner's Roblox Scripting Tutorial #10 - Events (Beginner to Pro 2019)
Вставка
- Опубліковано 28 вер 2024
- Beginner's Roblox Scripting Tutorial #10 - Events (Beginner to Pro 2019)
Hey guys, in today's video I am going to be teaching you about roblox events. or events in roblox. Basically, events are things that are fired whenever roblox sees them happen. So things like when a part is touched, or anything like that. These events are also called RBXScriptSignals, but no one ever calls them that so you can probably just remember events. Anyways I hope you guys enjoy the video and I'll see you in the next one!
Link to Beginner's Tutorial Series:
• Beginner's Roblox Scri...
-- Follow me on twitter! (my name is tapwater because thats my main channel): / realtapwater
- Join my Discord Server to learn and meet other developers!-
/ discord
--What is this series about and who is it for?
So this series is meant for people who really want to learn exactly how to script, if that is you then I promise by the time you watch this whole series you will know exactly how to script on roblox. Anyways be sure to subscribe to see whenever I release a new tutorial and I will see you guys in the next one. Peace!
Hey guys! Be sure to join the discord server if you have any questions or if you would like to meet me! discord.gg/FKcSyRh
hi can you teach me how to make a build mode system ike bloxburg
Ool man!
Hi I'm in 2020 right now and sadly this is out dated can you make a new Roblox scripting tutorial (Beginner's)
@@rumfel3 Is it really outdated?
game.Workspace.AwesomePart.Touched:Connect(function()
wait(7)
if AwesomePart.Anchored == true then
wait(2)
AwesomePart.Anchored = false
print"Ow you hurt me"
end
end)
WHY IS IT NOT WORKING
"I wasn't even busy I was just being lazy"
Lol this is a relatable thing XD
He was busy being lazy
@@kennytran2860 HA
same
Aye the man was straight so that's good
The fact he was honest about it.. +respect
1:28 I swear my boy was gonna put hotdog XD
Same
Lol
@@miker3715Welp just found my old account
took a bit honestly
Thanks man! As soon as this video started and I seen you put touched I instantly said "is this how you can make they team doors on they games?" and instantly tried coding that myself and it worked all because of your help as beginner as that sounds I was so proud xd
same with me but just doors in general
True, is beginners are like, Woah I made this! Pros be like, Oh cool
him: hey guys it’s the dev king
captions: hi guys it’s the deaf king
because captions are deaf
lol this is the only recent comment ive seen
Notice.
@@WildDreamer19 Notice
@@amiroto8449 Year 3: Notice
This guy has one of the most high understanding of teaching on UA-cam. I would recommend to finish his series 100%
To everyone watching this, make sure you give yourself mini-projects/assignments to do after learning something new! If you just watch without practice, you won't get better.
👍👍
i still don't know who joe is
@@worsenedcolor what?
I just write it down in notes and expirement with them
@@mech_electro thats a good way to learn
Thanks so much for this, after watching this series so far I think I'll finally be able to code something myself instead copypasting scripts from tutorials to get the stuff i want.
Yup. That is basically what I have been doing until I found out about these videos
Even though I'm watching this 4 years later, it helps so much. Thanks DevKing
Same here! This stuff really helps
same here
me too! just learning today, didn't know that roblox studio was a great game engine
lets be honest: when he said that you could go to the next tutorial
*you didn't*
Edit: for those missing context, at the end he said that you can go ahead to skip to the next video but nobody wanted to because we are learning scripting
This is false.
and a lot of other people probably think that it's false aswell
@@eternity-308 nah hes right because im about to go back and watch the first ten so i can correct my mistake of not writing anything down
lol
@@BottledSam oof I edited my comment. Forgot to add context
@@BottledSam how is it so far
Only a bit of people are here compared to the first episode, thanks for getting here!
i love your tutorials i made a simple door open when button touched script from your tutorials (my first script) so if u wanna review it then here it is
make sure you have a part called "Button" near a part called "Door" Resizing is optional
local door = game.Workspace.Door
local function open()
door.Transparency = 0.5
door.CanCollide = false
wait(3)
door.Transparency = 0
door.CanCollide = true
end
game.Workspace.Button.Touched:Connect(open)
good job!
your script helped me make a button that activates a color changing part
guys what he's trying to do towards the end does work but he just forgot wait(), anyways here's the script:
local function onTouched()
wait(1)
script.Parent.Anchored = false
wait(1)
script.Parent.Anchored = true
end
script.Parent.Touched:Connect(onTouched)
Your pfp got me
@@joshualee6852 imagine not using dark mode
The Blinking Brownie what in the f*** does that have to do with events?
@@crystalscreens9057 It has nothing to do with events, Joshua said that Person's profile picture got him. Well his profile picture is a fly sitting on a default picture with a white background. To be fooled by that you also need a white background which means Joshua did not use dark mode.
The Blinking Brownie and does it matter of we don't use dark mode? Sometimes people like the light more than the dark.
Im already know these functons and just watch this series because Im bored and dont have motivation to do something, but Im really impressed how good you can explain something. Good job, dude👍
thanks to your tutorials i made a working door using Events, if statements and object-oriented programming, huge thanks to you bud : )
2:24 was really helpful
i love how he makes it fun by adding in Hotdog as a variable every time :))
If you are gonna make a bunch of falling parts that have the same name use this because if you don't, only one of the parts are gonna fall, also instead of putting this into the workspace, put it into the part.
local function EpicFall()
script.Parent.Anchored = false
end
script.Parent.Touched:Connect(EpicFall)
A great roblox dev teacher always sets hotdog as an example.
its so perfect its like your friend explaining something to you
YO DUDE THANK YOU SO MUCH
I made it so if you don’t go up the staircase in time the part that your standing on will have CanCollide turned out off, so if you stand on a part too long (1 second) you will fall through but when you do the script will turn CanCollide on in 3 seconds so you can do it again without having it to be permanently disabled.
Thank you so much, although it’s not much you have helped me accomplish something I have never done before as a beginner in scripting.
+1 sub
Thank you
I like that the tutorials give clear instructions. The videos help me a lot, thanks!
Thank you for these, I really feeling like I'm getting somewhere quickly
for your testing at the end you had to do it with while true do :)
Bro you explain so well because of you I can code and script now thanks so much dude!
For the last part, i think the wait time of 1 second was short and by the time a second passed, the part already touched the ground. i kept a wait time of 0.5 seconds and it worked for me.
game.Workspace.Part.Anchored = true
local function anchorremoval()
game.Workspace.Part.Anchored = false
wait(0.5)
game.Workspace.Part.Anchored = true
end
local function start()
game.Workspace.Part.Touched:Connect(function()
anchorremoval()
end)
end
start()
If you have problems with the Part printing when touching the baseplate, you can also make it only run if the player touches it. (USES PARAMETERS)
game.Workspace.Banana.Touched:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit) then
print("Ahh!")
print(Hit)
end
end)
In line 1 When something touches the part, the touched event returns data to the parameter (Hit) the parameter will now equal to the data it sent eg. Left leg (Think of the parameter like a variable)
In line 2 The script checks to see if the body part that touched the part is a player (It checks for a player in the character, an NPC can be a character but it can't be a player) if it is a player it will run line 3
In line 3 it prints "don't touch me"
end
But to be honest Im not sure myself how line 2 works :')
in the second method of the touch event, how does one add parameters if they dont allow parenthesis
3:27 if from this script your function doesnt work just delete spaces that putted automaticly
Nice refresher for someone like me who forgets quite a bit
Tysm! I’m learning to code and this was really usefull!
Thanks to you I figured out how to script my game so then when you walk over The part it turns neon and Prints shine bright
rlly good tuts i literally made a obby and made that one glass game from squid game where u have to guess which one is safe
after i watched this, i decided to dig in more and managed to make it so when u touch the part it dissapears and when u dont touch it it reappears.
I know this might be an old vid but you inspired me to start my own ROBLOX channel!
btw why it didnt work at the end was because i dont know but it has to be like this part = game.Workspace.Part
local function yo()
part.Anchored = false
wait(1)
part.Anchored = true
end
part.Touched:Connect(yo)
Everyone here i wish you good luck to learn scripting I’m already a great at scripting I can make cool games so will you it only takes a month to learn like me and I’m still learning I will finish in 2 more months well it’s kinda hard because I need to learn by my self because the tutorials are finished and others are basic so good luck to you all
Thanks Dude, when you play around I learn alot.
from this tutorial I made this cool script (also my first every script kinda)
script.Parent.Touched:Connect(function()
if script.Parent.Touched then
script.Parent.Transparency = 0
end
end)
script.Parent.TouchEnded:Connect(function()
if script.Parent.TouchEnded then
script.Parent.Transparency = 1
end
end)
I’ve watched many many scripting tutorials of anything but mostly explaining events. Your video was the most useful and had the best and most straight-forward explanation, thank you!
game.Workspace.Block.Touched:Connect(function()
game.Workspace.Block.Anchored = false
print("Text")
end)
Totally gonna work
This series is so helpful 😭
thank you dev king you did a really great job explaining but I have a question: so when we are doing and event for something we can connect like a raw function into it?
to wait the function u need to move it below the end to work i belive
Do you have any sort of script or part of a video explaining how to make an NPC wander? Like it moves to random directions for a short time, then stops for a few seconds, and then continues walking. Somewhat similar to the way NPCs in Dinosaur Simulator move around.
yes watch my pathfinding tutorial
Idk if anyone will see this but for some reason, my text already appears once in the output when it only appears after u touch the part in the tutorial
See if u named the part not the floor because maybe u put all commands to execute on the floor
@@cr4zy989 yo I tried it, it worked tysm!
So far I have learnt so MUCH
I don’t know how to make my own scripts I understand the material but don’t know how I will use this to make my own script for my gamw
OMG REALLY GUD PLEASE DO MORE
bro i wrote the script oral it worked but without me touching it and i copied the whole script he wrote and it did the same thing
at the nd you can put remove() so it rmeoves itself so it goesnt make loads of print statements
i swear to god i cant remember the events thing
i have come back to this video atleast 6 times
finaly someone who can teach me how to code easily'
great videos
the last thing you tried did work, the wait aspect i mean. i think the problem was that you continued touching it so the function just kept running over and over again and setting anchored to false
It keeps running the event after I hit play, even if I never initially touch the brick. How do I fix the issue?
It doesn't matter whether a player touches it or a part touches it unless specified. is the part touching something else like the baseplate?
even tho this is kinda old it helped me learn coding
I am watching this while listening to It has to be this way
guys, the 'touched' event gets fired as soon as i spawn in without even touching it, is there a reason why?
edit: It was because it was touching the ground because it was already not anchored, but when i try to make it anchored, it stays anchored despite the function saying the anchor is false,
what should u do?
Events are soooo exciting lol!
I know im super late but can someone help explain what the word "game" at the beginning of the line do?
Game basically indicates the game that ur in. if you don't use it the script will break and not continue, hope this answer's your question
*Can someone please please tell me whats wrong with this?: : (*
local function PressingButton()
game.Workspace.Baseplate.Anchored = "false"
print("It is working tho?")
end
game.Workspace.Button.Touched:Connect(PressingButton)
Sorry i don't understand how to script
false shouldn't have " " so delete them. Also delete Button and replace it with Baseplate
10:23 reason that functiıon doesnt work its because you touch it multiple times and it run again again and again so when it tries to set anchored to true another run makes it false
how to remember all of this?
Write stuff down on like google docs or on a paper or something like that
practice it several times a day
try think of ways you can use this in a game and program it
Use brain
@@cazulon1122 lol
also after it does (''part name here'').Anchored = false how can u make it go back to its original place? im thinking of doing a remake of my obby whit harder stages and more obstacles and after finishing the obby im gonna try to do a zombie game (simple at start)
How do i get the wiki?
Guys I literally made a part where if you touch it another part becomes transparent and you can walk through it I’m so proud lol
Hey, How to reset an event??
For Example, I am building an obby and I used the script:
local function ThePart()
print ("Works!!")
game.Workspace.BoyOhBoy.Anchored = false
end
game.Workspace.BoyOhBoy.Touched:Connect(OKBRO)
And I wanted it to reset to the place where it was,
You know what I mean right??
Please answer :)
Notes:
If you go to view and find the object browser, you can see different events and other things you can use in code. Its better to use the wiki
Parts have children that are events. Events have lightning symbols.
After you type the event you type :connect(function()
This will make a function that is called when the event happens
Example:
Part.Touched:Connect(function()
Print (yes)
end)
And when you touch that part, then yes will be printed
If an event is ran, you can use a wait code, but if it’s ran again, the event wont wait, and it will restart the function from start. Another way to do this is
local function [insert the name of your function]()
[code]
end
part.Touched:Connect([insert name of your function])
thank you!!! All I had to learn about was some humaniod stuff and I could make a working kill brick for my obby!
Even tho you can just go free models and copy the script of a random kill block!
"Roblox has listeners in the game"
Kids: OmG rObLoX iS wAtChInG uS!!!!
I have a quick question. If I say, unanchored a part and it falls a bit. But after 2 seconds I want it to go back to the starting position. How do I make it go back up? An answer would be really great!
you are going to use the Vector3.new property.
local part = game.Workspace.Part
part.Anchored = false
wait(2)
part.Anchored = true
part.Position = Vector3.new(0,5,0)--this will set the part to a new position.
hope it helps!
@@zhyV thanks so much. That was really helpful
Thanks Bro, I have just on doubt how should I prevent the function from running multiple times?
I want to run it only once
ok so for some reason my part instantly falls
heres my code
local function fall()
print('Function Active')
game.Workspace.FallObject.Anchored = false
end
game.Workspace.FallObject.Touched:Connect(fall)
can anyone help me to make it fall only when its touched by a character?
You gotta click the anchored button
@@kiransaraf5849 thx
when i start the game, the part automatically changes color after i put the script, (i put a color change instead of a print one) anyone know a fix?
Is It Normal? If I Understand advanced coding Within 2-3weeks?
4:42 "What the function" 👏👏👏👏👏👏👏👏
I think i can confidently say that i will get nowhere trying to learn scripting and i am only wasting my time because i dont understand any of this so i guess ill just stick to playing games
im litterally watching all previous video and this midnight lol
You are amazing just saying
I Have a question and i am seeing the video 5 years later so DevKing Cant see my comment so please answer and my question is - Why Do We Have To Add Parentheses After Naming The Function?
It's mainly basic syntax but ask yourself this: if I ever want to set parameters for the function, how would my script know the difference between the function_name and the actual parameters themselves?
Also, removing the parentheses will generally give you an error(because you haven't followed the syntax)
Hope this helped.
Congrats who reached this far
I got a question. If I make the parts fall, how do I make them respawn?
in the output every time I run it automatically says the thing 2:36 but ur doesnt, how?
I have the same probelm
what about descendants and ancestry functions
when I execute this code it says passed value is not a function
Here is my code:
game.Workspace.Baseplate.Touched:Connect(function()
print("hej")
end)
I wanted to make a part change colors when touched and this is the code i used, is there any easier way to do it?
local function function4()
game.Workspace.Part.BrickColor=BrickColor.new("Light yellow")
end
local function function5()
game.Workspace.Part2.BrickColor=BrickColor.new("White")
end
local function function6()
game.Workspace.Part3.BrickColor=BrickColor.new("Brick yellow")
end
local function function7()
game.Workspace.Part4.BrickColor=BrickColor.new("Pastel Blue")
end
local function function8()
game.Workspace.Part5.BrickColor=BrickColor.new("Light reddish violet")
end
local function function9()
game.Workspace.Part6.BrickColor=BrickColor.new("Light reddish violet")
end
game.Workspace.Part.Touched:Connect(function4)
game.Workspace.Part2.Touched:Connect(function5)
game.Workspace.Part3.Touched:Connect(function6)
game.Workspace.Part4.Touched:Connect(function7)
game.Workspace.Part5.Touched:Connect(function8)
game.Workspace.Part6.Touched:Connect(function9)
game.Workspace.MyPart.Touched:Connect(function()
print("I was stepped on grr")
end)
-----------------------------------------------------------------------------------------------------------------------------------------------
My question is, why does it print the string in the output right away once I run the game and the part is unanchored, but it prints it when I touch it and it is anchored?
------------------------------------------------------------------------------------------------------------------------------------
It's because another part is touching "MyPart", a baseplate could touch "MyPart" and still trigger the code
@@TheMurcielago yeah and you should give him a way to make it work only for "players" if you can
@@TheMurcielago I never thought that would be possible, thank you so much for the explanation!
All other tutorials just dont feel the same and not motivating, but this guy's tutorials, they are just magic, I owe this man my entire developer career and motivation to be a developer.
he teaches really good and makes jokes so its entertaining
@@9kxrelocal hotdog = yourComment
local hotdog = facts
@@giraffelove12
If yourComment == facts then ()
you received a like from me
end
@@squash9189 I feel like I didnt even word it right because
if myComment == true then
print(“its true”)
else
print (“no”)
end
and it printed “no”
@@squash9189 correction:
local function GiveLike()
yourComment.Likes = 1
end
if yourComment.Facts == true then
GiveLike()
end
Whenever I learn from games, I payed for a game that teaches you to script I get headaches. Then I turn on your channel and suddenly it all makes sense...
He's like the Indian guy teaching you math but for scripting! Lol.
there is a new game called "scripting school", and it's free and very helpfull.
yes I replied after four years
I love your channel I just found it today and I already know soo much more! Thank you 😊
Gaming Guns sameeeeee 😄
Same.
Ikrr
Same
Thank you so much. At this episode I did a lot of scripting myself so much. I ended up making my own script where whenever you touch a block it turns red but whenever you get off it turns green bc its happy your not stepping or touching it anymore.
wow that's ADORABLE 🥺
awwww
Are you going to be teaching more events?
No
@@joshuajurado939 thanks you were just a year and a half late
@@Luke-db1ev 👨🏿👨🏿👱🏻♀️👨🏿👨🏿👨🏿🦳
"hope you know what i mean"
me : yes i hope too lol
Me as a noob oh so now we getting interesting ight I see how it is XD
Am barley getting started with scripting
Same!
But i also good modeler
Dude your tutorials are actually helping me learn a lot. I learned how to make the platform fall after a couple of seconds because of your videos.
bro its not that hard to make a platform get fall after a couple of seconds, even my lil bro can do it..
But I understand you, DevKing series is really helpful!..
@@fuzailgaming715 21 December 2022 💀💀💀
@@qarful7pardon, i dont understand
@@fuzailgaming715 pants pants got those ants
Another fantastic tutorial! I love how I not only learn something but also have a lot of fun learning it! :D
Same!!
im crying in shame while watching this video
I thought I could never learn how to script because of these bad tutorials. I only knew the print script a bit but that was it. Today I learned many things. Thank you so much. If I would ever get famous I would tell my viewers to subscribe to you :)
Bad tutorials from him????
so basically after watching this video and all other videos before it i decided to test what i can do and i did it 2 different ways one i set up 8 bricks where when you touch them they turn red and if all 8 brick are red then a coin appears in the middle and the second way im about to try is using the touch ended event when when the touch is ended the the coin is invisible but when touched it isn't and there is only one brick this time but you have to push something ontop of the brick and then get the coin
nice scripting
you kinda gave me a idea to make a script where like if u collect the coin it goes transparent so heres what i came up with im pretty proud of it:
local Coin = game.Workspace.Coin
local function CoinAppear()
Coin.Transparency = 0.2
end
local function CoinDisappear()
Coin.Transparency = 1
end
game.Workspace.Coin.Touched:Connect(CoinAppear)
game.Workspace.Coin.TouchEnded:Connect(CoinDisappear)
-- end
also im new to scripting so sorry if it isnt completely functional lol
You managed to fit something that usually takes hours to teach into just 10 minutes, if you say you are not one of the best Roblox scripters ever, you're lying.
i got mad because my script wasnt working until i noticed the function was not written wrtie lol this so helpful
Yeah you didnt spell it wrtie because of that