Summary: An event is a way to listen to an action occurring within the game and execute code once it is triggered. More technical data: 1. Ways to listen to events: - :Connect(): Listen to the event forever until the connection is disconnected. - :Once(): Listens for the event only once and disconnects automatically, and does not run again. - Wait(): Waits for the event to occur by blocking the code below where the event is waiting to be fired - ConnectParallel(): Used in parallel luau with actors 2. Event data type: Event data types are called RBXScriptSignal, while connections (when using :Connect() or otherwise), are called RBXScriptConnection. 3. Differences between RBXScriptSignal and RBXScriptConnection RBXScriptSignal are events that can be listened to with :Connect() or the other forms mentioned above. While RBXScriptConnection, is a connection that roblox gives us when we are listening to an event, it has a method called :Disconnect() that serves to stop listening to that event.
What does " Listen to the event forever" mean? Does it mean like the function will run everytime the event is fired? And how to disconnect the connection?
@@الخلبوصة it means that i will stay listening to the event in memory until it gets disconnected. And to disconnect it you do: local event = someEvent:Connect(function()end) event:Disconnect() -- disconnects the event, it wont be listening to the event in memory
Your explanation is clear and to the point. Thank you so much! Keep posting these summary comments in every video BrawlDev uploads, you don't know how beneficial they are to me. Didn't know that there are type of things called Once, Wait and ConnectParallel. And I now understand how they work!
Now I want you to iimagine you're playing Minecraft and your exploring a jungle temple filled with all these trip wires that are inside of the temple, you decide to step on it and it triggers a dispenser that shoots you with multiple arrows that you didnt see coming at all
I've been watching your guide but never really posted my learning objectives but I'm really proud of what I did today so here I am posting it in case it helps someone :D! So basically I wanted to make some blocks that changed a sphere's color when you touch them. I created 7 different colors (Green, red, yellow, blue, pink, purple and white) and here is the script I made: local Ball = game.Workspace.TestColor.Sphere local green = game.Workspace.TestColor.Green local pink = game.Workspace.TestColor.Pink local purple = game.Workspace.TestColor.Purple local blue = game.Workspace.TestColor.Blue local red = game.Workspace.TestColor.Red local yellow = game.Workspace.TestColor.Yellow local white = game.Workspace.TestColor.White local greent = false local pinkt = false local purplet = false local bluet = false local redt = false local yellt = false local whitet = false -- the t after every color basically stands for "touched" -- The next part is basically the same as the video shows but insted of printing the part that touched I changed the ball's color green.Touched:Connect(function(otherPart) if greent == false then greent = true Ball.BrickColor = BrickColor.new("Mint") wait (3)
greent = false end end) pink.Touched:Connect(function(otherPart) if pinkt == false then pinkt = true Ball.BrickColor = BrickColor.new("Carnation pink") wait (3) pinkt = false end end) purple.Touched:Connect(function(otherPart) if purplet == false then purplet = true Ball.BrickColor = BrickColor.new("Alder") wait (3) purplet = false end end) blue.Touched:Connect(function(otherPart) if bluet == false then bluet = true Ball.BrickColor = BrickColor.new("Cyan") wait (3) bluet = false end end) red.Touched:Connect(function(otherPart) if redt == false then redt = true Ball.BrickColor = BrickColor.new("Persimmon") wait (3) redt = false end end) yellow.Touched:Connect(function(otherPart) if yellt == false then yellt = true Ball.BrickColor = BrickColor.new("Cool yellow") wait (3) yellt = false end end) white.Touched:Connect(function(otherPart) if whitet == false then whitet = true Ball.BrickColor = BrickColor.new("Institutional white") wait (3) whitet = false end end)
Your Tutorials are so helpful !! I started scripting 2 days ago and this is what I did: This is a color changing and material changing event :))) local touchPart = game.Workspace.TouchPart touchPart.Touched:Connect(function() print (“This part is touched.”) if partIsTouched == false then partIsTouched = true touchPart.Material = Enum.Material.Neon print(“Neon.”) touchPart.BrickColor = BrickColor.Random () print(“Color changed to:” ..tostring(touchPart.BrickColor)) wait (5) partIsTouched = false touchPart.Material = Enum.Material.Mud print(“Back to normal!”) end end)
use task.wait, it has less load on the server if u do (difference is task.wait waits for server to catch up and wait forces the server to stop and do it absolutely in 5 seconds which can cause more lag/issue for the server
11:31 my understanding on why you have to set partIsTouched = true even when you have task.wait(2), is that the event is always firing infinitely fast. An analogy I made is that the first time the event fires is like the first fish in a fish school to cross the finish line. If partIsTouched = true wasn't there, then the second fish will still instantly cross the finish line since the event is always firing. Thus, we have to set the relative global variable partIsTouched to true to prevent any more event firings to get past that if statement.
something IMPORTANT he forgot to mention is if you go to the view tab then open object browser it tells you lots about events and other things when scripting.
@AlexanderEdwards-x8e "PartIsTouched == false" checks IF it's false. "PartIsTouched = false" STATES that it's false. Basically, == checks it, while = declares it
i used Touch event to make a part change its color to green from red and found TouchEnded event and used it to make it red whenever you arent touching it since it was pretty self explanetory ive already gottren some education in coding in diffirent languages like phyton or and seen about this kind of ui before too so i knew about coding or at least how it works and stuff. this episode is the first episode with features that i never saw before. i hope it wont be a problem lol. btw its crazy that you only have 10k subs when im watching. gl w tht
Made a speedboost + 10 seconds timer so the speedboost will stop when it reaches to 0 local Speedboost = script.Parent Speedboost.Touched:Connect(function(otherpart) local humanoid = otherpart.Parent:FindFirstChild("Humanoid") if humanoid then humanoid.WalkSpeed = 100 if humanoid.WalkSpeed == 100 then for i = 10, 0, -1 do task.wait(1) print("Timer ", i) if i == 0 then print("Speedboost is over!") humanoid.WalkSpeed = 16
end end end end wait(10) humanoid.WalkSpeed = 16 end)
Kinda proud of what I did today basically I made a wedge that changes color when u press it or whatever had to do some de-bugging and this is what happened :D local wedge = game.Workspace.Wedge local partIsTouched = false wedge.Touched:Connect(function() if partIsTouched == false then partIsTouched = true print("Touched") wedge.BrickColor = BrickColor.new("Really red") wait(1) wedge.BrickColor = BrickColor.new("Really blue") print("Untouched") partIsTouched = false end end)
a good learning activity is at the end try to explain the code to urself and see if u can explain every bit of function the code does for what reason. this is a good activity to familiarise urslef with scripting!
local touchPart = game.Workspace.Part local isTouched = false game.Workspace.Part.Touched:Connect(function(otherPart) local x = math.random(1, 10) local y = math.random(1, 10) local z = math.random(1, 10) if isTouched == false then isTouched = true print(otherPart.Name) touchPart.CFrame = CFrame.new(x, y, z) task.wait(.5) isTouched = false end
end) its such a basic script, but it made me feel so proud when i managed to figure it out by myself. basically what it does is everytime you touch a part, it will teleport to a random position within a 1 to 10 value range for each axis. this could probably be done in a better way but idc, i've been trying to learn roblox game dev ever since i was a little kid, and finally getting the impulse to ACTUALLY begin learning the proper way makes me feel so happy! game dev is literally my DREAM profession! thanks brawldev! :D
@@memebirbs thanks for the little compliment! i actually improved alot from when i had posted this comment, looking back at it kinda of makes me cringe, lol.
@@Kodul i made a few meme games for my friends, nothing i can call real games yet. i am working on an actual game for a change although i actually had quite a few projects that could be considered real enjoyable games but i gave up on them cuz i cant model that well. rn im just trying to focus on getting atleast one of them done.
one of those things that are built into Roblox. just like game and workspace. roblox knows what all of these things already are. we are constantly editing our game which is why we have to tell roblox what all these edits mean. example, we have a part named myPart we can't just write myPart and expect roblox to know what it is because we've edited something. that's why we tell roblox what it is by saying: local myPart = game.Workspace.Part
i made a simple thing where when you touch a hitbox, another part changes color and has a cooldown of 3 seconds local touchPart = game.Workspace.TouchPart local isPartTouch = false touchPart.Touched:Connect(function(otherPart) if isPartTouch == false then isPartTouch = true game.Workspace.fallpart.BrickColor = BrickColor.Random() task.wait(3) isPartTouch = false end end) this is my first time sharing my work, only cause im genuinely proud of this
Thanks so much for your help, I have tried other tutorials and failed to learn anything or very little. Anyways this is what I did in Studio! local TouchPart = game.Workspace.KillTest local partIsTouched = false TouchPart.Touched:Connect(function(otherPart) if partIsTouched == false then partIsTouched = true task.wait(1) TouchPart.BrickColor = BrickColor.new("Really red") task.wait(1) TouchPart.BrickColor = BrickColor.new("Bright blue") if partIsTouched == true then print("The function has been completed") end end end)
took me very long to figure this out but i got it local touchpart = game.Workspace.TouchPart local partistouched = false local partistouched = true touchpart.Touched:Connect(function(otherpart)
local touchpart = game.Workspace.touchpart local partistouched = false local partmaterial = false touchpart.Touched:Connect(function(otherpart) if partistouched == false then partistouched = true print(otherpart.Name)
task.wait(2) partistouched = false
if partmaterial == false then touchpart.Material = "Rock" task.wait(2) partmaterial = true else touchpart.Material = "Plastic" end end end)
That step is called Debouncing. The reason it's needed in this scenario is because when the Touched event is fired, there are many of the Player's parts touching the part really quickly with no cooldown. This can cause lag issues in your game. To add a Debounce in your script, you need to create a BOOLEAN variable and set it to false, like: local partIsTouched = false Then, create an If statement to check if the part is being touched or not, and set the variable to TRUE once it is being touched: if partIsTouched == false then partIsTouched = true print(otherPart.Name) Next, set it back to FALSE once it is NOT being touched anymore: if partIsTouched == false then partIsTouched = true print(otherPart.Name) task.wait(2) -- you can edit how long you want the cooldown to be for the Touched event to occur here partIsTouched = false end
I spent like 30 minutes perfecting this lol but here is my art work that I'm proud off. local touchPart = game.Workspace.Eek local originalMaterial = touchPart.Material local partIsTouched = false touchPart.Touched:Connect(function(otherPart) if not partIsTouched then partIsTouched = true print("Ah hah, metal!") task.wait(2) touchPart.Material = Enum.Material.Metal task.wait(2) print("Oh? You want it to become the original material and a different color? Alright.") task.wait(2) touchPart.Material = originalMaterial task.wait(2) touchPart.BrickColor = BrickColor.new("Cyan") task.wait(2) print("You want more!?!? Jeez.") task.wait(2) touchPart.Transparency = 0.5 task.wait(2) print("Oh now what? You want the transparency back to normal? Ugh.") task.wait(2) touchPart.Transparency = 0 task.wait(2) print("Are you FINALLY done now?!?") task.wait(2) print("Finally...") partIsTouched = false end end)
im so glad this script accually worked, thank you so much for making a free and easy way to learn coding local touchPart = game.Workspace.touchPart local partistouched = false touchPart.Touched:connect(function(player) -- makes the part unAnchored when a player touches it if partistouched == false then touchPart.Anchored = false end end)
Hi, been watching your tutorials since episode 1 and been experimenting each episode and really wanted to share it but i'm shy lol but i'm proud of what i was able to do for this episode so might as well share it: local touchPart = game.Workspace.Part local partTouched = false touchPart.Touched:Connect(function(darkGreen) if partTouched == false then partTouched = true for i = 0.9, 0, -0.1 do touchPart1.Transparency = i task.wait(0.1) end touchPart.Transparency = 0 print('Dark Green!') end end) so like the color of the part is dark green and initially the part's transparency is 0.9 so when you touch the part, it slowly turns the transparency to 0. After the part's transparency turns to 0 then it will print the color of the part which is dark green. I used what I learnt in the Loops Episode #11 and combined it with what I learnt in this episode :>>
Your guide so far has helped me understand the fundamentals better than any other guide I've tried so far! I just wanted to ask!! I see there are two unavailable videos hidden on the playlist, are these important at all? If this is the end of the playlist I want to move on to your other playlists on the more advanced topics, but I wanted to make sure there was nothing I was missing! Scripting is something I've had my mind on for many years so I'd want to learn it as best as I can!
Have patience. Learning these concepts, especially the advanced ones, takes time to get really good at. And yes, there are more episodes left. The series will end around ep 17-18 and then we'll be returning back to the advanced and gui series!
@@BrawlDevRBLX Cool! I actually peeked ahead and followed the first three videos of the advanced series just out of curiosity, and stopped after the tools episode since I had had my fun with making silly tools with what I knew. I'll definitely keep an eye out on this series first though since some of the things, though I did have a general understanding of what they did, caught me off guard with not knowing exactly how to use them! This has been a great learning series though! You've actually explained what each individual thing does which really helps me stay motivated and understand WHY it's actually working, which other guides I've tried to follow in the past just simply did not do and killed my motivation! Keep it up, you've got at least one person here really following along to learn!
So i made my block to where if i touch the block it changes the avatar color to the color i set rather than actually chaning the block color 😆 i did this all by accident to
3:54 you can do game.Players.PlayerAdded:Connect(function(player) print("A new player has joined into the game! Player:", player) end) instead if you are feeling fancy lol
So I actually did touch events before I watched this tutorial and here's what I did: I went into workshop and searched up kill brick and put it into roblox studio then I went into it's script and copied the bit which looked like the touched event, after I put it into a bridge model from the workshop and made a bridge that disappears when you walk on it. here the script: script.Parent.Touched:Connect(function(part) if part.Parent:FindFirstChild("Humanoid") then task.wait(0.7) game.Workspace.WoodenBridge.CanCollide = false game.Workspace.WoodenBridge.Transparency = 0.5 task.wait(4) game.Workspace.WoodenBridge.CanCollide = true game.Workspace.WoodenBridge.Transparency = 0 end end)
I made a block that turns green when you touch it :D local touchPart = game.Workspace.touchPart local partIsTouched = false touchPart.Touched:Connect(function(otherPart) if partIsTouched == false then partIsTouched = true touchPart.BrickColor = BrickColor.new("Bright green") task.wait(2) touchPart.BrickColor = BrickColor.new("Medium stone grey") task.wait(2) partIsTouched = false end
change the color of the brick randomly every time u touch it local TouchPart = game.Workspace.TouchPart local partIsTouched = false TouchPart.Touched:Connect(function(otherPart) if partIsTouched == false then partIsTouched = true print(otherPart.Name)
local killbrick = script.Parent local cooldown = false killbrick.Touched:Connect(function(touched) local humanoid = touched.Parent:FindFirstChild("Humanoid")
if humanoid and not cooldown then cooldown = true killbrick.BrickColor = BrickColor.new("Really red") task.wait(1) killbrick.BrickColor = BrickColor.new("Neon orange") task.wait(1) killbrick.BrickColor = BrickColor.new("Fire Yellow") task.wait(1) killbrick.BrickColor = BrickColor.new("Dark green") task.wait(1) killbrick.BrickColor = BrickColor.new("Baby blue") task.wait(1) killbrick.BrickColor = BrickColor.new("Bright purple") task.wait(1) cooldown = false end end)
Made it so that my part changes its rarity (Becomes a different color and prints a rarity) when you interact with it, and it has 1 second cool-down local touchpart = game.Workspace.Touchpart local Partouched = false touchpart.Touched:Connect(function(otherpart) local z = math.random(1,100) if Partouched == false then Partouched = true if z
local touchpart = game.Workspace.LAVA local partIsTouched = false touchpart.Touched:Connect(function(otherPart) if partIsTouched == false then partIsTouched = true print(otherPart) otherPart:Destroy() task.wait(0.1) partIsTouched = false end end)
i made one that is a normal touched event and also a clicked event that changes color randomly touched event local WPart = game.Workspace.WPart local touched = false WPart.Touched:Connect(function(cool) if touched == false then touched = true WPart.BrickColor = BrickColor.Random() print(WPart.BrickColor) task.wait(2) touched = false end end) clicked event (Part Needs ClickDetector To Work) local WPart = game.Workspace.WPart local clicked = false WPart.ClickDetector.MouseClick:Connect(function(cool) if clicked == false then clicked = true WPart.BrickColor = BrickColor.Random() print(WPart.BrickColor) task.wait(2) clicked = false end end)
I edited the TouchedEvent code and added this which basically when the player has touched the part, the transparency will be set to 1 and CanCollide will be off, once 2 second cooldown is done, it will change back to Transparency 0 and the part will have CanCollide On: local hitPart = game.Workspace.HitPart local partIsTouched = false hitPart.Touched:Connect(function(otherPart) if partIsTouched == false then partIsTouched = true print(otherPart.Name) hitPart.Transparency = 1 hitPart.CanCollide = false task.wait(2) partIsTouched = false hitPart.Transparency = 0 hitPart.CanCollide = true hitPart.BrickColor = BrickColor.new("Really red") end end)
local touchPart = game.Workspace.touchPart local partTouched = false touchPart.Touched:Connect(function(otherPart) if partTouched == false then partTouched = true touchPart.BrickColor = BrickColor.Random()
wait(2) partTouched = false end
end) local baseplate = game.Workspace.Baseplate game.Players.PlayerAdded:Connect(function(player) if game.Players.PlayerAdded:Connect() then baseplate.BrickColor = BrickColor.Random() end end) *OR YOU CAN USE CODE FROM LAST VIDEO AND MAKE IT LOOP" local baseplate = game.Workspace.Baseplate game.Players.PlayerAdded:Connect(function(player) for player = 1, 9999999 do baseplate.BrickColor = BrickColor.Random() wait(1) end end)
i needed a LOT of practicw with this one. here they are (they work combined as a part that hates when it gets touched and wants u to leave and calls u lil bro idk. game.Players.PlayerAdded:Connect(function(player) print("get out please") print(player) end) game.Players.PlayerRemoving:Connect(function(player) print("yippe") end) local t = game.Workspace.touch local touched = false t.Touched:Connect(function(otherpart) if touched == false then touched = true task.wait(1) touched = false end if touched == true then print("EW I SAID GET OUT NOT TOUCH ME LIL BRO") else print("i said get out lil bro") end end)
i was making my script : local TouchPart = game.Workspace.TouchPart TouchPart.Touched:Connect(function(OtherPart) print(OtherPart.Name) end) and for some reason it didnt work then when i hovered my mouse over the variable it highlighted the TouchPart the second one then i renamed the variable then it turned out you cant have the same name of the variable as a part why is that
@@MR-VOXELATOR117 you CAN have a variable the same name as a part. The reason yours didn't work is because you probably didn't even touch the part in game. The script itself will work.
local touchPart = game.Workspace.TouchPart local partIsTouched = false local baseplate = game.Workspace.Baseplate touchPart.Touched:Connect(function(otherPart) if partIsTouched == false then partIsTouched = true baseplate.BrickColor = BrickColor.new("Really red")
if touchPart.TouchEnded then touchPart.TouchEnded:Connect(function() partIsTouched = false baseplate.BrickColor = BrickColor.new("Dark grey metallic") end) end end partIsTouched = false
A trick obby part (this took awhile) local TrickPart = game.Workspace.TrickPart TrickPart.Touched:Connect(function(whatTouched) if whatTouched.Parent:FindFirstChild("Humanoid") then-- this detects if what touched Trik part is part of the player while TrickPart.Transparency < 1 do TrickPart.Transparency = math.min(TrickPart.Transparency + 0.1, 1)-- makes sure Transparency can't be more than 1 wait(0.25) end TrickPart.CanCollide = false wait(5) TrickPart.CanCollide = true TrickPart.Transparency = 0 end end)
It works for me in this way: local touchPart = game.Workspace.TouchPart local canTouchPart = true local function isTouchedPart(otherpart) if canTouchPart == true then canTouchPart = false print(otherpart.Name)
task.wait(2) canTouchPart = true end end touchPart.Touched:Connect(isTouchedPart) Also amazing tutorial!
local touchPart = game.Workspace.Touchpart local partistouched = false touchPart.Touched:Connect(function(otherpart) if partistouched == false then partistouched = true print(otherpart.Name) task.wait(0.25) partistouched = false if partistouched == false then touchPart.BrickColor = BrickColor.new("Medium stone Grey") partistouched = true touchPart.BrickColor = BrickColor.new("Really red") task.wait(0.75) partistouched = false touchPart.BrickColor = BrickColor.new("Medium stone Grey") end end end) Thank you so much Brawl dev, Im really dedicated to becoming a game developer and these tutorials are great, Thank you :)
--a cool example of triggering events! local part = game.Workspace.TouchedPart local touchedpart = false part.Touched:Connect(function(TouchedPart) local humanoid = TouchedPart.Parent:GetFullName() if touchedpart == false then touchedpart = true print(TouchedPart.Parent)
local touchPart = game.Workspace.TouchPart local partIsTouched = false touchPart.Touched:Connect(function(otherPart) if partIsTouched == false then partIsTouched = true print(otherPart.Name)
task.wait(3) partIsTouched = false end end) touchPart.Touched:Connect(function(otherPart) if partIsTouched == false then partIsTouched = true touchPart.BrickColor = BrickColor.new("Sea green") task.wait(3) touchPart.BrickColor = BrickColor.new("Really red") partIsTouched = false end end)
OK THIS IS LITERALLY WHY I STARTED LEARNING SCRIPTING with no prior scripting learning by your 13th tutorial of the play list i can finally do this: local AntiFog = game.Workspace.AntiFogPart local AntiTouched = AntiFog.Touched:Connect(function(bodypart) AntiFog.CanCollide = false AntiFog.Transparency = 1 if AntiFog.CanCollide == false then game.Lighting.Atmosphere.Density = 0.0 end end) a part called 'AntiFogPart' is placed in a building so theres no fog in the building' local AntiFog = game.Workspace.AntiFogPart local OnFog = game.Workspace.OnFogPart local OnTouched = OnFog.Touched:Connect(function(bodypart) OnFog.CanCollide = false OnFog.Transparency = 1 if OnFog.CanCollide == false then game.Lighting.Atmosphere.Density = 0.6 end end) a part called 'OnFogPart' is placed in the spot where it teleports me outside of the building, despite now reaching my goal ill carry on learning how to script, but i have to say, THANK YOU!
oh btw, i was struggling so i clicked 'tab' and it auto pasted a lot of the struggle in for me (idk how else to make the script work without some of the unnecissery stuff)
A contraption you go in and get smushed by a large piece of metal: local touchpart = workspace["Squish contraption"].TouchPart local metal = workspace["Squish contraption"].Metal local wall = workspace["Squish contraption"].Wall metal.Anchored = true local partisTouched = false touchpart.Touched:Connect(function(otherpart) if partisTouched == false then partisTouched = true print("uh oh, here it comes.") wall.CanCollide = true wall.Transparency = 0 metal.Anchored = false task.wait(.1) partisTouched = false end end)
day4, this one also was really cool to learn. i see how both of these are insanely useful allready, especially with creating objects that fall on touch like most obbies have. Aswell as join messages to players. heres what i cooked up local platform1 = game.Workspace.Platform1 local partIsTouched = false platform1.Touched:Connect(function(otherPart) if partIsTouched == false then partIsTouched = true
task.wait(1) print("the part is going to fall!") platform1.BrickColor = BrickColor.new("Really red") platform1.Transparency = 0.5 task.wait (2) platform1.Anchored = false platform1.Transparency = 0.75 print("the part fell!") task.wait (1) platform1.Transparency = 1 end end)
9:31 Ok so I didn't understand the "partIsTouched" part at first but for the people that struggle like me I'm pretty sure what it does is he makes the variable FALSE and when you touch the part it can only do the second line when the variable is FALSE and it is so it prints the part name but it first makes it TRUE and so when you move while it's giving the part name and waiting a second it cannot give the name again because it is still on TRUE and after the waiting it resets too FALSE. Sorry you prob still don't understand it if you didn't alr.
made this into two parts just to test out the cooling time for when you touch a part. (in this case i have made it the spawn location) game.Players.PlayerAdded:connect(function(player) print('a new player has joined') print(player) end) local spawnTouch = game.Workspace.SpawnLocation spawnTouch.touched:Connect(function(otherpart) print(otherpart.name) end) the script bellow includes cooling time. :D game.Players.PlayerAdded:connect(function(player) print('a new player has joined') print(player) end) local spawnTouch = game.Workspace.SpawnLocation local spawnIsTouched= false spawnTouch.touched:Connect(function(otherpart) if spawnIsTouched == false then spawnIsTouched = true print(otherpart.Name)
task.wait(2) spawnIsTouched = false end end) just want to add that these videos are so great! easy to follow. here and there i can feel a small challenge but its not so frustrating to the point i want to stop. maybe they way brawlDev breaks it down is just to good!
for some reason the first event code to do with touchpart in the vid insta kills me when i touch it even though i only asked it to print name? can i get some help please
I've done this but once the touchPart is touched once it doesn't work again and I was wondering if you would be able to let me know what I need to do for it to continuously work (so that every time the touchPart is touched it turns transparent) local touchPart = game.Workspace["Touch part"] local partIsTouched = false touchPart.Touched:Connect(function(otherPart) if partIsTouched == false then partIsTouched = true touchPart.Transparency = 0.5 if partIsTouched == true then task.wait(2) touchPart.Transparency = 0 end task.wait(2) end end)
11:45 when you said "You can even change the color of the part and even make it turn back after a period of time," I laterally did that exactly before you even said that 😭 Here's the code: -- Making it so when a player touches the "Bad Brick" it makes it red local touchBadPart = game.Workspace.BadPart local BadPartIsTouched = false touchBadPart.Touched:Connect(function(otherPart) if BadPartIsTouched == false then BadPartIsTouched = true
touchBadPart.BrickColor = BrickColor.new("Really red") wait(2) touchBadPart.BrickColor = BrickColor.new("Medium stone grey")
local touchPart = game.Workspace.TouchPart local partIsTouched = false touchPart.Touched:Connect(function(otherpart) --sense anything touching part if partIsTouched == false then partIsTouched = true print(otherpart) -- show what touched part touchPart.Size = touchPart.Size + Vector3.new(1,1,1) --grow wait(2) -- debounce partIsTouched = false end end)
I will post my first script here, so I'm sorry if it's too long. This script will basically change the part called "TouchPart" to blue if you touch it once, to yellow if you touch it twice, to red if you touch it three times, and finally destroy the object Note 1: Instead of using three different if statements, I would probably create a dictionary holding the counter values and their respective colors, something like {"1": Cyan, "2": Yellow, "3": Red}. The code would be more optimized and readable, but I don't know how to do it in Lua, so yeah 😅 Note 2: Instead of repeating the same code snippet to toggle the isTouched variable and change the color, a better practice would be to create a function. But unfortunately, I was too lazy to do it game.Players.PlayerAdded:Connect(function(player) print(player.Name .. " connected!") end) local TouchPart = game.Workspace.TouchPart local isTouched = false local Counter = 0 TouchPart.Touched:Connect(function(otherPart) if isTouched == false then Counter += 1 isTouched = true task.wait(2) end if Counter == 1 then TouchPart.BrickColor = BrickColor.new(0.184314, 0.67451, 1) isTouched = true task.wait(2) TouchPart.BrickColor = BrickColor.new(1, 1, 1) isTouched = false end if Counter == 2 then TouchPart.BrickColor = BrickColor.new(0.961, 0.804, 0.189) isTouched = true task.wait(2) TouchPart.BrickColor = BrickColor.new(1, 1, 1) isTouched = false end if Counter == 3 then TouchPart.BrickColor = BrickColor.new(0.769, 0.157, 0.110) isTouched = true task.wait(2) isTouched = false TouchPart:Destroy() end end)
i made it when a player touches the coin, made by me. it disappears and then it plays some boss music and the siren alarm meme also plays and when the player turns around there is a leprechaun that says Where me gold? and its supposed to fight you.
Here is a lua script that changes color every second -- Get a reference to the part this script is in local part = script.Parent -- Function to change the color of the part when touched local function onTouch(other) -- Change the color of the part to a random color part.BrickColor = BrickColor.Random() end -- Connect the onTouch function to the Touched event of the part part.Touched:Connect(onTouch)
So events automatically pass in the parameter to the connected function right? Like when you touch the part, the event passes the thing that touched the part into the function.
11:13 Yessir done local tw = game.Workspace.touchyWouchy local twbeingTouched = false -- boolean variable used to make a cooldown in the touched event tw.Touched:Connect(function(OtherPart) if twbeingTouched == false then -- basically runs the if statement if its touched twbeingTouched = true -- runs because it got touched
print(OtherPart.Name) -- prints the name of the part that touched it. tw.BrickColor = BrickColor.new("Ghost grey") -- messing with the properties of the part when its touched tw.Material = Enum.Material.Brick tw.CastShadow = false tw.Transparency = 0.420 task.wait(2.5)
twbeingTouched = false -- if its stops being touched it properties will go back to normal
if twbeingTouched == false then tw.BrickColor = BrickColor.new("Medium stone grey") -- rests the properties back to normal if its not touched tw.Material = Enum.Material.Plastic tw.CastShadow = true tw.Transparency = 0 end end end) -- what this script does is if you stop touching the part after 2.5 seconds it will reset back to normal -- episode 13 done yessir :D.
This took me maybe 10 mins to figure out mainly due to what to use and where to put certain lines local partistouched = false local count = 1 local TouchColor = game.Workspace.TouchColor TouchColor.Touched:Connect(function(otherpart) if partistouched == false then partistouched = true print(otherpart.Name) if count == 1 then TouchColor.BrickColor = BrickColor.Red() print("R") count = count + 1 elseif count == 2 then TouchColor.BrickColor = BrickColor.Blue() print("B") count = count + 1 elseif count == 3 then TouchColor.BrickColor = BrickColor.Yellow() print("Y") count = 1 end wait(2) partistouched = false end end) Ur first touch will make it red, next blue then third yellow and then back to red etcc
you actually can do script.parent.Touched:Connect(function() instead of local (part name) = game.workspace.(part name) ' (part name.Touched:Connect(function() parent is a thing that own it like you have script in a part so script.parent is script and the owner of it so it is the part
With this tutorial i was able to make a sleeping cube that when you touch it he says "Hey!" and wakes up, i used billboard gui for the text, this is what my script looks like: local Cube = script.Parent Cube.Talk["Hey!"].Visible = false script.Parent.Touched:Connect(function(Speak) Cube.Awake.Transparency = 0 Cube.Asleep.Transparency = 1 Cube.Talk["Hey!"].Visible = true task.wait(3) Cube.Awake.Transparency = 1 Cube.Asleep.Transparency = 0 Cube.Talk["Hey!"].Visible = false end)
This helped me. heres the script i made. local touchPart = game.Workspace.TouchPart local partIsTouch = false touchPart.Touched:Connect(function(otherPart) if partIsTouch == false then partIsTouch = true print("Part is touched") print(otherPart.Name) touchPart.Material = Enum.Material.Neon touchPart.BrickColor = BrickColor.Random()
task.wait(2) partIsTouch = false touchPart.Material = Enum.Material.Plastic touchPart.BrickColor = BrickColor.new("Medium stone grey") print("The part is back to normal!") end end)
local touch = game.Workspace.touch local touched = false touch.Touched:Connect(function(otherPart) if not touched then touched = true print(otherPart.Name) -- Change color to a random color every time it's touched touch.Color = BrickColor.Random().Color -- Reset touched flag after a short delay task.wait(1) touched = false end end)
local touchPart = game.Workspace.Touchpart local partistouched = false touchPart.Touched:connect(function(otherpart) if partistouched == false then partistouched = true print("you have touched it") task.wait("10") partistouched = false end end)
to change the colour of a part randomly when you touch it with a cooldown of 2 seconds: local Part = game.Workspace.Part local sphereTouched = false Part.Touched:Connect(function(thePart) if sphereTouched == false then sphereTouched = true Part.BrickColor = BrickColor.Random()
local touch = game.Workspace.Part local touchingpart = false touch.Touched:Connect(function(otherpart) if touchingpart == false then touchingpart = true touch.Transparency = 0.9 end wait(1) touch.Transparency = 0 touchingpart = false end) This script is pretty cool cuz whenever i touch the part it makes it almost dissapear for 2 secs try it out :)
i basically made an code that turns the part invisible and untouchable/uncollideable, and then after 5 seconds it turns visible again and touchable/collideable, and it doesnt turn invisible instantly, its bit by bit local touchPart = game.Workspace.TouchPart touchPart.Anchored = true touchPart.CanTouch = true touchPart.CanCollide = true touchPart.BrickColor = BrickColor.Red() touchPart.Transparency = 0 touchPart.Touched:Connect(function(otherPart) touchPart.CanTouch = false for i = 0, 10, 1 do touchPart.Transparency = i/10 task.wait(0.1) if i == 10 then touchPart.CanCollide = false task.wait(5) touchPart.Transparency = 0 touchPart.CanCollide = true touchPart.CanTouch = true end end end)
Summary:
An event is a way to listen to an action occurring within the game and execute code once it is triggered.
More technical data:
1. Ways to listen to events:
- :Connect(): Listen to the event forever until the connection is disconnected.
- :Once(): Listens for the event only once and disconnects automatically, and does not run again.
- Wait(): Waits for the event to occur by blocking the code below where the event is waiting to be fired
- ConnectParallel(): Used in parallel luau with actors
2. Event data type:
Event data types are called RBXScriptSignal, while connections (when using :Connect() or otherwise), are called RBXScriptConnection.
3. Differences between RBXScriptSignal and RBXScriptConnection
RBXScriptSignal are events that can be listened to with :Connect() or the other forms mentioned above. While RBXScriptConnection, is a connection that roblox gives us when we are listening to an event, it has a method called :Disconnect() that serves to stop listening to that event.
What does " Listen to the event forever" mean?
Does it mean like the function will run everytime the event is fired?
And how to disconnect the connection?
@@الخلبوصة it means that i will stay listening to the event in memory until it gets disconnected. And to disconnect it you do:
local event = someEvent:Connect(function()end)
event:Disconnect() -- disconnects the event, it wont be listening to the event in memory
Your explanation is clear and to the point. Thank you so much!
Keep posting these summary comments in every video BrawlDev uploads, you don't know how beneficial they are to me.
Didn't know that there are type of things called Once, Wait and ConnectParallel. And I now understand how they work!
perfect for my smooth brain
@@osakadev I’m so confused by the PartIsTouched == false then PartIsTouched=false
Can someone please explain it to me?
Now I want you to iimagine you're playing Minecraft and your exploring a jungle temple filled with all these trip wires that are inside of the temple, you decide to step on it and it triggers a dispenser that shoots you with multiple arrows that you didnt see coming at all
Literally minecraft
Now I see how they code it (most likely because there is a difference between coding language)
@@ZoneBlox I’m so confused by the PartIsTouched == false then PartIsTouched=false
Can someone please explain it to me?
@AlexanderEdwards-x8e It's supposed to be:
if partIsTouched == false then
partIsTouched = true
@BottledAxolotl but I don’t get it, so if there is no one touching the part, then there is someone touching the part
0:07 today is actually my birthday lol
hsppy late birthday bro
thought i was the only one watching this later
@@inoxxz same
guess im the most late here
Happy Late Birthday
I've been watching your guide but never really posted my learning objectives but I'm really proud of what I did today so here I am posting it in case it helps someone :D!
So basically I wanted to make some blocks that changed a sphere's color when you touch them. I created 7 different colors (Green, red, yellow, blue, pink, purple and white) and here is the script I made:
local Ball = game.Workspace.TestColor.Sphere
local green = game.Workspace.TestColor.Green
local pink = game.Workspace.TestColor.Pink
local purple = game.Workspace.TestColor.Purple
local blue = game.Workspace.TestColor.Blue
local red = game.Workspace.TestColor.Red
local yellow = game.Workspace.TestColor.Yellow
local white = game.Workspace.TestColor.White
local greent = false
local pinkt = false
local purplet = false
local bluet = false
local redt = false
local yellt = false
local whitet = false
-- the t after every color basically stands for "touched"
-- The next part is basically the same as the video shows but insted of printing the part that touched I changed the ball's color
green.Touched:Connect(function(otherPart)
if greent == false then
greent = true
Ball.BrickColor = BrickColor.new("Mint")
wait (3)
greent = false
end
end)
pink.Touched:Connect(function(otherPart)
if pinkt == false then
pinkt = true
Ball.BrickColor = BrickColor.new("Carnation pink")
wait (3)
pinkt = false
end
end)
purple.Touched:Connect(function(otherPart)
if purplet == false then
purplet = true
Ball.BrickColor = BrickColor.new("Alder")
wait (3)
purplet = false
end
end)
blue.Touched:Connect(function(otherPart)
if bluet == false then
bluet = true
Ball.BrickColor = BrickColor.new("Cyan")
wait (3)
bluet = false
end
end)
red.Touched:Connect(function(otherPart)
if redt == false then
redt = true
Ball.BrickColor = BrickColor.new("Persimmon")
wait (3)
redt = false
end
end)
yellow.Touched:Connect(function(otherPart)
if yellt == false then
yellt = true
Ball.BrickColor = BrickColor.new("Cool yellow")
wait (3)
yellt = false
end
end)
white.Touched:Connect(function(otherPart)
if whitet == false then
whitet = true
Ball.BrickColor = BrickColor.new("Institutional white")
wait (3)
whitet = false
end
end)
yo i dont want to steal your idea but i tried it and it really helped me understand more abou this topic thanks
BRO CALM DOWN
@@rafaeldossantos1998 Happy to hear that ^^!
@@UserBananaIDK hehe
That's a cool script ! And i was wondering why do you keep "otherPart" in each function parameter
this is very useful, as a dev myself I really need all the info I can get for scripting since its hell to learn and this helps a lot!
I’m so confused by the PartIsTouched == false then PartIsTouched=false
Can someone please explain it to me?
Your Tutorials are so helpful !!
I started scripting 2 days ago and this is what I did:
This is a color changing and material changing event :)))
local touchPart = game.Workspace.TouchPart
touchPart.Touched:Connect(function()
print (“This part is touched.”)
if partIsTouched == false then
partIsTouched = true
touchPart.Material = Enum.Material.Neon
print(“Neon.”)
touchPart.BrickColor = BrickColor.Random ()
print(“Color changed to:” ..tostring(touchPart.BrickColor))
wait (5)
partIsTouched = false
touchPart.Material = Enum.Material.Mud
print(“Back to normal!”)
end
end)
use task.wait, it has less load on the server if u do (difference is task.wait waits for server to catch up and wait forces the server to stop and do it absolutely in 5 seconds which can cause more lag/issue for the server
thank you. this helped me understand it better
u didnt add PartIsTouched == false at first
i think you forgot to add variables, does it still work tho?
how im struggling so hard
11:31 my understanding on why you have to set partIsTouched = true even when you have task.wait(2), is that the event is always firing infinitely fast. An analogy I made is that the first time the event fires is like the first fish in a fish school to cross the finish line. If partIsTouched = true wasn't there, then the second fish will still instantly cross the finish line since the event is always firing. Thus, we have to set the relative global variable partIsTouched to true to prevent any more event firings to get past that if statement.
Thanks
something IMPORTANT he forgot to mention is if you go to the view tab then open object browser it tells you lots about events and other things when scripting.
I’m so confused by the PartIsTouched == false then PartIsTouched=false
Can someone please explain it to me?
@AlexanderEdwards-x8e "PartIsTouched == false" checks IF it's false. "PartIsTouched = false" STATES that it's false. Basically, == checks it, while = declares it
@@questionmark.4444 ahhh thanks
1:16 brawldev is a robot confirmed??
That’s what I was thinking lol
i wasnt expecting another episode today WWWW!!!
keep up with the amazing content!
i used Touch event to make a part change its color to green from red and found TouchEnded event and used it to make it red whenever you arent touching it since it was pretty self explanetory
ive already gottren some education in coding in diffirent languages like phyton or and seen about this kind of ui before too so i knew about coding or at least how it works and stuff. this episode is the first episode with features that i never saw before. i hope it wont be a problem lol. btw its crazy that you only have 10k subs when im watching. gl w tht
I'm learning python rn and it's pretty cool, I think I can learn Lua too :)
today is my bday and i just watched the example of the start of the video lol
Happy Birthday!
@@MrPicklekvGygA thank you!!!!
omg
This is my favorite video of the beginner series so far!
Made a speedboost + 10 seconds timer so the speedboost will stop when it reaches to 0
local Speedboost = script.Parent
Speedboost.Touched:Connect(function(otherpart)
local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed = 100
if humanoid.WalkSpeed == 100 then
for i = 10, 0, -1 do
task.wait(1)
print("Timer ", i)
if i == 0 then
print("Speedboost is over!")
humanoid.WalkSpeed = 16
end
end
end
end
wait(10)
humanoid.WalkSpeed = 16
end)
omg its fr my birthday today what a blessing
From 9:34 to 10:45 I was bamboozled
Kinda proud of what I did today basically I made a wedge that changes color when u press it or whatever had to do some de-bugging and this is what happened :D
local wedge = game.Workspace.Wedge
local partIsTouched = false
wedge.Touched:Connect(function()
if partIsTouched == false then
partIsTouched = true
print("Touched")
wedge.BrickColor = BrickColor.new("Really red")
wait(1)
wedge.BrickColor = BrickColor.new("Really blue")
print("Untouched")
partIsTouched = false
end
end)
7k subscribers, Congrats 🎉❤
a good learning activity is at the end try to explain the code to urself and see if u can explain every bit of function the code does for what reason. this is a good activity to familiarise urslef with scripting!
local touchPart = game.Workspace.Part
local isTouched = false
game.Workspace.Part.Touched:Connect(function(otherPart)
local x = math.random(1, 10)
local y = math.random(1, 10)
local z = math.random(1, 10)
if isTouched == false then
isTouched = true
print(otherPart.Name)
touchPart.CFrame = CFrame.new(x, y, z)
task.wait(.5)
isTouched = false
end
end)
its such a basic script, but it made me feel so proud when i managed to figure it out by myself. basically what it does is everytime you touch a part, it will teleport to a random position within a 1 to 10 value range for each axis. this could probably be done in a better way but idc, i've been trying to learn roblox game dev ever since i was a little kid, and finally getting the impulse to ACTUALLY begin learning the proper way makes me feel so happy! game dev is literally my DREAM profession! thanks brawldev! :D
actually this script is really cool! its really impressive you made this on your own, i took a little spin to where it changes color instead of moving
@@memebirbs thanks for the little compliment! i actually improved alot from when i had posted this comment, looking back at it kinda of makes me cringe, lol.
@Contentdeleted99998 have you made your own game yet?
@@Kodul i made a few meme games for my friends, nothing i can call real games yet. i am working on an actual game for a change although i actually had quite a few projects that could be considered real enjoyable games but i gave up on them cuz i cant model that well. rn im just trying to focus on getting atleast one of them done.
@Contentdeleted99998 I wish you good luck
amazing video im just curious are u gonna make another new advanced series since u also made a new beginners series
There won't be a new advanced series
In 4:51 how did the function knew or that roblox new the parameter is player name???
one of those things that are built into Roblox. just like game and workspace. roblox knows what all of these things already are. we are constantly editing our game which is why we have to tell roblox what all these edits mean.
example, we have a part named myPart
we can't just write myPart and expect roblox to know what it is because we've edited something.
that's why we tell roblox what it is by saying:
local myPart = game.Workspace.Part
i made a simple thing where when you touch a hitbox, another part changes color and has a cooldown of 3 seconds
local touchPart = game.Workspace.TouchPart
local isPartTouch = false
touchPart.Touched:Connect(function(otherPart)
if isPartTouch == false then
isPartTouch = true
game.Workspace.fallpart.BrickColor = BrickColor.Random()
task.wait(3)
isPartTouch = false
end
end)
this is my first time sharing my work, only cause im genuinely proud of this
I made a print statement that says “ y/n has joined the server!”
And a block that makes the player die (:
I thought there's nothing I don't know regarding Events, until this video released.
Thank you brawldev!
Amazing tutorials love them
Thanks so much for your help, I have tried other tutorials and failed to learn anything or very little. Anyways this is what I did in Studio!
local TouchPart = game.Workspace.KillTest
local partIsTouched = false
TouchPart.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
task.wait(1)
TouchPart.BrickColor = BrickColor.new("Really red")
task.wait(1)
TouchPart.BrickColor = BrickColor.new("Bright blue")
if partIsTouched == true then
print("The function has been completed")
end
end
end)
took me very long to figure this out but i got it
local touchpart = game.Workspace.TouchPart
local partistouched = false
local partistouched = true
touchpart.Touched:Connect(function(otherpart)
if partistouched == true then
touchpart.BrickColor = BrickColor.Random()
end
touchpart.TouchEnded:Connect(function(otherpart)
if partistouched == true then
touchpart.BrickColor = BrickColor.Gray()
end
end)
end)
bro this tutorial is so actually gooddd, i didn't know anything with scripts now im playing w them!!!!
local touchpart = game.Workspace.touchpart
local partistouched = false
local partmaterial = false
touchpart.Touched:Connect(function(otherpart)
if partistouched == false then
partistouched = true
print(otherpart.Name)
task.wait(2)
partistouched = false
if partmaterial == false then
touchpart.Material = "Rock"
task.wait(2)
partmaterial = true
else
touchpart.Material = "Plastic"
end
end
end)
Thanks brawl dev I made a part that slowly sets its transparency to 1, then collision gets turned off. Very cool!
I’m so confused by the PartIsTouched == false then PartIsTouched=false
Can someone please explain it to me?
That step is called Debouncing. The reason it's needed in this scenario is because when the Touched event is fired, there are many of the Player's parts touching the part really quickly with no cooldown. This can cause lag issues in your game. To add a Debounce in your script, you need to create a BOOLEAN variable and set it to false, like:
local partIsTouched = false
Then, create an If statement to check if the part is being touched or not, and set the variable to TRUE once it is being touched:
if partIsTouched == false then
partIsTouched = true
print(otherPart.Name)
Next, set it back to FALSE once it is NOT being touched anymore:
if partIsTouched == false then
partIsTouched = true
print(otherPart.Name)
task.wait(2) -- you can edit how long you want the cooldown to be for the Touched event to occur here
partIsTouched = false
end
could you tell me why it printed Player instead of the playername.Thankyou
You write print(player) and not print("player")
@@Pizzadude690 thank you
0:07 i dont need to imagine it, because it is today.
I spent like 30 minutes perfecting this lol but here is my art work that I'm proud off.
local touchPart = game.Workspace.Eek
local originalMaterial = touchPart.Material
local partIsTouched = false
touchPart.Touched:Connect(function(otherPart)
if not partIsTouched then
partIsTouched = true
print("Ah hah, metal!")
task.wait(2)
touchPart.Material = Enum.Material.Metal
task.wait(2)
print("Oh? You want it to become the original material and a different color? Alright.")
task.wait(2)
touchPart.Material = originalMaterial
task.wait(2)
touchPart.BrickColor = BrickColor.new("Cyan")
task.wait(2)
print("You want more!?!? Jeez.")
task.wait(2)
touchPart.Transparency = 0.5
task.wait(2)
print("Oh now what? You want the transparency back to normal? Ugh.")
task.wait(2)
touchPart.Transparency = 0
task.wait(2)
print("Are you FINALLY done now?!?")
task.wait(2)
print("Finally...")
partIsTouched = false
end
end)
im so glad this script accually worked, thank you so much for making a free and easy way to learn coding
local touchPart = game.Workspace.touchPart
local partistouched = false
touchPart.Touched:connect(function(player) -- makes the part unAnchored when a player touches it
if partistouched == false then
touchPart.Anchored = false
end
end)
good job bro
I wish the best for you bro your pretty smart I’ve been watching all the videos and still struggling
Hi, been watching your tutorials since episode 1 and been experimenting each episode and really wanted to share it but i'm shy lol but i'm proud of what i was able to do for this episode so might as well share it:
local touchPart = game.Workspace.Part
local partTouched = false
touchPart.Touched:Connect(function(darkGreen)
if partTouched == false then
partTouched = true
for i = 0.9, 0, -0.1 do
touchPart1.Transparency = i
task.wait(0.1)
end
touchPart.Transparency = 0
print('Dark Green!')
end
end)
so like the color of the part is dark green and initially the part's transparency is 0.9 so when you touch the part, it slowly turns the transparency to 0. After the part's transparency turns to 0 then it will print the color of the part which is dark green. I used what I learnt in the Loops Episode #11 and combined it with what I learnt in this episode :>>
A fix to your loop could be by adding a
partTouched = false
outside the if statement.
Your guide so far has helped me understand the fundamentals better than any other guide I've tried so far! I just wanted to ask!! I see there are two unavailable videos hidden on the playlist, are these important at all? If this is the end of the playlist I want to move on to your other playlists on the more advanced topics, but I wanted to make sure there was nothing I was missing! Scripting is something I've had my mind on for many years so I'd want to learn it as best as I can!
Have patience. Learning these concepts, especially the advanced ones, takes time to get really good at. And yes, there are more episodes left. The series will end around ep 17-18 and then we'll be returning back to the advanced and gui series!
@@BrawlDevRBLX Cool! I actually peeked ahead and followed the first three videos of the advanced series just out of curiosity, and stopped after the tools episode since I had had my fun with making silly tools with what I knew. I'll definitely keep an eye out on this series first though since some of the things, though I did have a general understanding of what they did, caught me off guard with not knowing exactly how to use them!
This has been a great learning series though! You've actually explained what each individual thing does which really helps me stay motivated and understand WHY it's actually working, which other guides I've tried to follow in the past just simply did not do and killed my motivation! Keep it up, you've got at least one person here really following along to learn!
So i made my block to where if i touch the block it changes the avatar color to the color i set rather than actually chaning the block color 😆 i did this all by accident to
3:54 you can do
game.Players.PlayerAdded:Connect(function(player)
print("A new player has joined into the game! Player:", player)
end)
instead if you are feeling fancy lol
or
game.Players.PlayerAdded:Connect(function(player)
print(player.. " has joined the game.")
end)
if you are feeling extra fancy
@@NaCubical true
So I actually did touch events before I watched this tutorial and here's what I did: I went into workshop and searched up kill brick and put it into roblox studio then I went into it's script and copied the bit which looked like the touched event, after I put it into a bridge model from the workshop and made a bridge that disappears when you walk on it. here the script:
script.Parent.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
task.wait(0.7)
game.Workspace.WoodenBridge.CanCollide = false
game.Workspace.WoodenBridge.Transparency = 0.5
task.wait(4)
game.Workspace.WoodenBridge.CanCollide = true
game.Workspace.WoodenBridge.Transparency = 0
end
end)
You are the besttt🎉🎉🎉
I made a block that turns green when you touch it :D local touchPart = game.Workspace.touchPart
local partIsTouched = false
touchPart.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
touchPart.BrickColor = BrickColor.new("Bright green")
task.wait(2)
touchPart.BrickColor = BrickColor.new("Medium stone grey")
task.wait(2)
partIsTouched = false
end
end)
Hey Dude thanks for teaching me!
So what I learned is that I can continuously touch your parts with my Humanoid Root Part :)
change the color of the brick randomly every time u touch it
local TouchPart = game.Workspace.TouchPart
local partIsTouched = false
TouchPart.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
print(otherPart.Name)
TouchPart.BrickColor = BrickColor.Random()
task.wait(3)
partIsTouched = false
end
end)
local killbrick = script.Parent
local cooldown = false
killbrick.Touched:Connect(function(touched)
local humanoid = touched.Parent:FindFirstChild("Humanoid")
if humanoid and not cooldown then
cooldown = true
killbrick.BrickColor = BrickColor.new("Really red")
task.wait(1)
killbrick.BrickColor = BrickColor.new("Neon orange")
task.wait(1)
killbrick.BrickColor = BrickColor.new("Fire Yellow")
task.wait(1)
killbrick.BrickColor = BrickColor.new("Dark green")
task.wait(1)
killbrick.BrickColor = BrickColor.new("Baby blue")
task.wait(1)
killbrick.BrickColor = BrickColor.new("Bright purple")
task.wait(1)
cooldown = false
end
end)
Made it so that my part changes its rarity (Becomes a different color and prints a rarity) when you interact with it, and it has 1 second cool-down
local touchpart = game.Workspace.Touchpart
local Partouched = false
touchpart.Touched:Connect(function(otherpart)
local z = math.random(1,100)
if Partouched == false then
Partouched = true
if z
local touchpart = game.Workspace.LAVA
local partIsTouched = false
touchpart.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
print(otherPart)
otherPart:Destroy()
task.wait(0.1)
partIsTouched = false
end
end)
i made one that is a normal touched event and also a clicked event that changes color randomly
touched event
local WPart = game.Workspace.WPart
local touched = false
WPart.Touched:Connect(function(cool)
if touched == false then
touched = true
WPart.BrickColor = BrickColor.Random()
print(WPart.BrickColor)
task.wait(2)
touched = false
end
end)
clicked event (Part Needs ClickDetector To Work)
local WPart = game.Workspace.WPart
local clicked = false
WPart.ClickDetector.MouseClick:Connect(function(cool)
if clicked == false then
clicked = true
WPart.BrickColor = BrickColor.Random()
print(WPart.BrickColor)
task.wait(2)
clicked = false
end
end)
local touchedpart = false
game.Workspace.Part.Touched:Connect(function(PlayerPart)
if touchedpart == false then
touchedpart = true
game.Workspace.Part.BrickColor = BrickColor.new("Really red") --cooldown
game.Workspace.Baseplate.BrickColor = BrickColor.Random()
task.wait(3)
game.Workspace.Part.BrickColor = BrickColor.new("Lime green") -- off cooldown
touchedpart = false
end
end)
I edited the TouchedEvent code and added this which basically when the player has touched the part, the transparency will be set to 1 and CanCollide will be off, once 2 second cooldown is done, it will change back to Transparency 0 and the part will have CanCollide On: local hitPart = game.Workspace.HitPart
local partIsTouched = false
hitPart.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
print(otherPart.Name)
hitPart.Transparency = 1
hitPart.CanCollide = false
task.wait(2)
partIsTouched = false
hitPart.Transparency = 0
hitPart.CanCollide = true
hitPart.BrickColor = BrickColor.new("Really red")
end
end)
local touchPart = game.Workspace.touchPart
local partTouched = false
touchPart.Touched:Connect(function(otherPart)
if partTouched == false then
partTouched = true
touchPart.BrickColor = BrickColor.Random()
wait(2)
partTouched = false
end
end)
local baseplate = game.Workspace.Baseplate
game.Players.PlayerAdded:Connect(function(player)
if game.Players.PlayerAdded:Connect() then
baseplate.BrickColor = BrickColor.Random()
end
end)
*OR YOU CAN USE CODE FROM LAST VIDEO AND MAKE IT LOOP"
local baseplate = game.Workspace.Baseplate
game.Players.PlayerAdded:Connect(function(player)
for player = 1, 9999999 do
baseplate.BrickColor = BrickColor.Random()
wait(1)
end
end)
i needed a LOT of practicw with this one. here they are (they work combined as a part that hates when it gets touched and wants u to leave and calls u lil bro idk.
game.Players.PlayerAdded:Connect(function(player)
print("get out please")
print(player)
end)
game.Players.PlayerRemoving:Connect(function(player)
print("yippe")
end)
local t = game.Workspace.touch
local touched = false
t.Touched:Connect(function(otherpart)
if touched == false then
touched = true
task.wait(1)
touched = false
end
if touched == true then
print("EW I SAID GET OUT NOT TOUCH ME LIL BRO")
else
print("i said get out lil bro")
end
end)
you can actually do
print(player, "get out please")
so it says your name and says get out please
@@reaklaz oh cool, ill note that thx
very bad script ngl
@@MG-ji1ms hes new what did you expect?
@@MG-ji1ms man constructive criticism and move on with ur day
i was making my script :
local TouchPart = game.Workspace.TouchPart
TouchPart.Touched:Connect(function(OtherPart)
print(OtherPart.Name)
end)
and for some reason it didnt work then when i hovered my mouse over the variable it highlighted the TouchPart the second one then i renamed the variable then it turned out you cant have the same name of the variable as a part why is that
You need to have small t when making a variable so that it is not the same as the part
@@SkibidiDaca123 ohk
@@MR-VOXELATOR117 you CAN have a variable the same name as a part. The reason yours didn't work is because you probably didn't even touch the part in game. The script itself will work.
wish I could show you the progress I've made on my game, I'm making mad progress in just a week
local touchPart = game.Workspace.TouchPart
local partIsTouched = false
local baseplate = game.Workspace.Baseplate
touchPart.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
baseplate.BrickColor = BrickColor.new("Really red")
if
touchPart.TouchEnded then
touchPart.TouchEnded:Connect(function()
partIsTouched = false
baseplate.BrickColor = BrickColor.new("Dark grey metallic")
end)
end
end
partIsTouched = false
end)
Now this is getting interesting, bro just teached me how to do a hitbox!!!
A trick obby part (this took awhile)
local TrickPart = game.Workspace.TrickPart
TrickPart.Touched:Connect(function(whatTouched)
if whatTouched.Parent:FindFirstChild("Humanoid") then-- this detects if what touched Trik part is part of the player
while TrickPart.Transparency < 1 do
TrickPart.Transparency = math.min(TrickPart.Transparency + 0.1, 1)-- makes sure Transparency can't be more than 1
wait(0.25)
end
TrickPart.CanCollide = false
wait(5)
TrickPart.CanCollide = true
TrickPart.Transparency = 0
end
end)
It works for me in this way:
local touchPart = game.Workspace.TouchPart
local canTouchPart = true
local function isTouchedPart(otherpart)
if canTouchPart == true then
canTouchPart = false
print(otherpart.Name)
task.wait(2)
canTouchPart = true
end
end
touchPart.Touched:Connect(isTouchedPart)
Also amazing tutorial!
local touchPart = game.Workspace.Touchpart
local partistouched = false
touchPart.Touched:Connect(function(otherpart)
if partistouched == false then
partistouched = true
print(otherpart.Name)
task.wait(0.25)
partistouched = false
if partistouched == false then
touchPart.BrickColor = BrickColor.new("Medium stone Grey")
partistouched = true
touchPart.BrickColor = BrickColor.new("Really red")
task.wait(0.75)
partistouched = false
touchPart.BrickColor = BrickColor.new("Medium stone Grey")
end
end
end)
Thank you so much Brawl dev, Im really dedicated to becoming a game developer and these tutorials are great, Thank you :)
--a cool example of triggering events!
local part = game.Workspace.TouchedPart
local touchedpart = false
part.Touched:Connect(function(TouchedPart)
local humanoid = TouchedPart.Parent:GetFullName()
if touchedpart == false then
touchedpart = true
print(TouchedPart.Parent)
task.wait(2)
touchedpart = false
end
end)
local touchPart = game.Workspace.TouchPart
local partIsTouched = false
touchPart.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
print(otherPart.Name)
task.wait(3)
partIsTouched = false
end
end)
touchPart.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
touchPart.BrickColor = BrickColor.new("Sea green")
task.wait(3)
touchPart.BrickColor = BrickColor.new("Really red")
partIsTouched = false
end
end)
the fact that my birthday is in 2 days is crazy 0:05
OK THIS IS LITERALLY WHY I STARTED LEARNING SCRIPTING
with no prior scripting learning by your 13th tutorial of the play list i can finally do this:
local AntiFog = game.Workspace.AntiFogPart
local AntiTouched = AntiFog.Touched:Connect(function(bodypart)
AntiFog.CanCollide = false
AntiFog.Transparency = 1
if AntiFog.CanCollide == false then
game.Lighting.Atmosphere.Density = 0.0
end
end)
a part called 'AntiFogPart' is placed in a building so theres no fog in the building'
local AntiFog = game.Workspace.AntiFogPart
local OnFog = game.Workspace.OnFogPart
local OnTouched = OnFog.Touched:Connect(function(bodypart)
OnFog.CanCollide = false
OnFog.Transparency = 1
if OnFog.CanCollide == false then
game.Lighting.Atmosphere.Density = 0.6
end
end)
a part called 'OnFogPart' is placed in the spot where it teleports me outside of the building, despite now reaching my goal ill carry on learning how to script, but i have to say, THANK YOU!
oh btw, i was struggling so i clicked 'tab' and it auto pasted a lot of the struggle in for me (idk how else to make the script work without some of the unnecissery stuff)
A contraption you go in and get smushed by a large piece of metal:
local touchpart = workspace["Squish contraption"].TouchPart
local metal = workspace["Squish contraption"].Metal
local wall = workspace["Squish contraption"].Wall
metal.Anchored = true
local partisTouched = false
touchpart.Touched:Connect(function(otherpart)
if partisTouched == false then
partisTouched = true
print("uh oh, here it comes.")
wall.CanCollide = true
wall.Transparency = 0
metal.Anchored = false
task.wait(.1)
partisTouched = false
end
end)
day4, this one also was really cool to learn. i see how both of these are insanely useful allready, especially with creating objects that fall on touch like most obbies have. Aswell as join messages to players. heres what i cooked up
local platform1 = game.Workspace.Platform1
local partIsTouched = false
platform1.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
task.wait(1)
print("the part is going to fall!")
platform1.BrickColor = BrickColor.new("Really red")
platform1.Transparency = 0.5
task.wait (2)
platform1.Anchored = false
platform1.Transparency = 0.75
print("the part fell!")
task.wait (1)
platform1.Transparency = 1
end
end)
im tweaking
9:31 Ok so I didn't understand the "partIsTouched" part at first but for the people that struggle like me I'm pretty sure what it does is he makes the variable FALSE and when you touch the part it can only do the second line when the variable is FALSE and it is so it prints the part name but it first makes it TRUE and so when you move while it's giving the part name and waiting a second it cannot give the name again because it is still on TRUE and after the waiting it resets too FALSE.
Sorry you prob still don't understand it if you didn't alr.
made this into two parts just to test out the cooling time for when you touch a part. (in this case i have made it the spawn location)
game.Players.PlayerAdded:connect(function(player)
print('a new player has joined')
print(player)
end)
local spawnTouch = game.Workspace.SpawnLocation
spawnTouch.touched:Connect(function(otherpart)
print(otherpart.name)
end)
the script bellow includes cooling time. :D
game.Players.PlayerAdded:connect(function(player)
print('a new player has joined')
print(player)
end)
local spawnTouch = game.Workspace.SpawnLocation
local spawnIsTouched= false
spawnTouch.touched:Connect(function(otherpart)
if spawnIsTouched == false then
spawnIsTouched = true
print(otherpart.Name)
task.wait(2)
spawnIsTouched = false
end
end)
just want to add that these videos are so great! easy to follow. here and there i can feel a small challenge but its not so frustrating to the point i want to stop. maybe they way brawlDev breaks it down is just to good!
TY so much i made my own killbrick with this
for some reason the first event code to do with touchpart in the vid insta kills me when i touch it even though i only asked it to print name? can i get some help please
I've done this but once the touchPart is touched once it doesn't work again and I was wondering if you would be able to let me know what I need to do for it to continuously work (so that every time the touchPart is touched it turns transparent)
local touchPart = game.Workspace["Touch part"]
local partIsTouched = false
touchPart.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
touchPart.Transparency = 0.5
if partIsTouched == true then
task.wait(2)
touchPart.Transparency = 0
end
task.wait(2)
end
end)
you gotta remove the second task.wait
11:45 when you said "You can even change the color of the part and even make it turn back after a period of time," I laterally did that exactly before you even said that 😭
Here's the code:
-- Making it so when a player touches the "Bad Brick" it makes it red
local touchBadPart = game.Workspace.BadPart
local BadPartIsTouched = false
touchBadPart.Touched:Connect(function(otherPart)
if BadPartIsTouched == false then
BadPartIsTouched = true
touchBadPart.BrickColor = BrickColor.new("Really red")
wait(2)
touchBadPart.BrickColor = BrickColor.new("Medium stone grey")
task.wait(2)
BadPartIsTouched = false
end
end)
local touchPart = game.Workspace.TouchPart
local partIsTouched = false
touchPart.Touched:Connect(function(otherpart) --sense anything touching part
if partIsTouched == false then
partIsTouched = true
print(otherpart) -- show what touched part
touchPart.Size = touchPart.Size + Vector3.new(1,1,1) --grow
wait(2) -- debounce
partIsTouched = false
end
end)
normally when i want to learn to script i quit after 1 or 2 eps and now im up to 13
Bro you are the best scripting teacher ever
local touchPart = game.Workspace.TouchPart
local partIsTouched = false
local colorChangeAllowed = false
touchPart.Touched:Connect(function(otherPart)
if partIsTouched == false then
partIsTouched = true
print(otherPart.Name)
touchPart.BrickColor = BrickColor.new("Medium red")
-- Wait for 2 seconds
task.wait(2)
-- Allow color change on next touch
colorChangeAllowed = true
partIsTouched = false
elseif colorChangeAllowed then
touchPart.BrickColor = BrickColor.new("Medium blue")
colorChangeAllowed = false
-- Wait for 2 seconds
task.wait(2)
end
end)
I will post my first script here, so I'm sorry if it's too long. This script will basically change the part called "TouchPart" to blue if you touch it once, to yellow if you touch it twice, to red if you touch it three times, and finally destroy the object
Note 1: Instead of using three different if statements, I would probably create a dictionary holding the counter values and their respective colors, something like {"1": Cyan, "2": Yellow, "3": Red}. The code would be more optimized and readable, but I don't know how to do it in Lua, so yeah 😅
Note 2: Instead of repeating the same code snippet to toggle the isTouched variable and change the color, a better practice would be to create a function. But unfortunately, I was too lazy to do it
game.Players.PlayerAdded:Connect(function(player)
print(player.Name .. " connected!")
end)
local TouchPart = game.Workspace.TouchPart
local isTouched = false
local Counter = 0
TouchPart.Touched:Connect(function(otherPart)
if isTouched == false then
Counter += 1
isTouched = true
task.wait(2)
end
if Counter == 1 then
TouchPart.BrickColor = BrickColor.new(0.184314, 0.67451, 1)
isTouched = true
task.wait(2)
TouchPart.BrickColor = BrickColor.new(1, 1, 1)
isTouched = false
end
if Counter == 2 then
TouchPart.BrickColor = BrickColor.new(0.961, 0.804, 0.189)
isTouched = true
task.wait(2)
TouchPart.BrickColor = BrickColor.new(1, 1, 1)
isTouched = false
end
if Counter == 3 then
TouchPart.BrickColor = BrickColor.new(0.769, 0.157, 0.110)
isTouched = true
task.wait(2)
isTouched = false
TouchPart:Destroy()
end
end)
i made it when a player touches the coin, made by me. it disappears and then it plays some boss music and the siren alarm meme also plays and when the player turns around there is a leprechaun that says Where me gold? and its supposed to fight you.
Here is a lua script that changes color every second
-- Get a reference to the part this script is in
local part = script.Parent
-- Function to change the color of the part when touched
local function onTouch(other)
-- Change the color of the part to a random color
part.BrickColor = BrickColor.Random()
end
-- Connect the onTouch function to the Touched event of the part
part.Touched:Connect(onTouch)
So events automatically pass in the parameter to the connected function right? Like when you touch the part, the event passes the thing that touched the part into the function.
For built-in Roblox events, yes. Custom events you'll have to do yourself, but that's a bit more complicated to do.
@@BrawlDevRBLX ok Thank you so much
local touchPart = game.Workspace.TouchPart
local partIsTouched = false
touchPart.Touched:Connect(function(otherPart)
print(otherPart.Name)
otherPart.Color = Color3.fromRGB(255,255, 0)
end)
made myself yellow
😆
I made a player count with this! And it shows the players name on a gui!
11:13 Yessir done
local tw = game.Workspace.touchyWouchy
local twbeingTouched = false -- boolean variable used to make a cooldown in the touched event
tw.Touched:Connect(function(OtherPart)
if twbeingTouched == false then -- basically runs the if statement if its touched
twbeingTouched = true -- runs because it got touched
print(OtherPart.Name) -- prints the name of the part that touched it.
tw.BrickColor = BrickColor.new("Ghost grey") -- messing with the properties of the part when its touched
tw.Material = Enum.Material.Brick
tw.CastShadow = false
tw.Transparency = 0.420
task.wait(2.5)
twbeingTouched = false -- if its stops being touched it properties will go back to normal
if twbeingTouched == false then
tw.BrickColor = BrickColor.new("Medium stone grey") -- rests the properties back to normal if its not touched
tw.Material = Enum.Material.Plastic
tw.CastShadow = true
tw.Transparency = 0
end
end
end)
-- what this script does is if you stop touching the part after 2.5 seconds it will reset back to normal
-- episode 13 done yessir :D.
i had realy fun with the touched i realy tested to do it on my own till this part 13 but i kept getting errors thanks i finnaly made waht i wanted
This took me maybe 10 mins to figure out mainly due to what to use and where to put certain lines
local partistouched = false
local count = 1
local TouchColor = game.Workspace.TouchColor
TouchColor.Touched:Connect(function(otherpart)
if partistouched == false then
partistouched = true
print(otherpart.Name)
if count == 1 then
TouchColor.BrickColor = BrickColor.Red()
print("R")
count = count + 1
elseif count == 2 then
TouchColor.BrickColor = BrickColor.Blue()
print("B")
count = count + 1
elseif count == 3 then
TouchColor.BrickColor = BrickColor.Yellow()
print("Y")
count = 1
end
wait(2)
partistouched = false
end
end)
Ur first touch will make it red, next blue then third yellow and then back to red etcc
you actually can do script.parent.Touched:Connect(function() instead of local (part name) = game.workspace.(part name) ' (part name.Touched:Connect(function() parent is a thing that own it like you have script in a part so script.parent is script and the owner of it so it is the part
With this tutorial i was able to make a sleeping cube that when you touch it he says "Hey!" and wakes up, i used billboard gui for the text, this is what my script looks like:
local Cube = script.Parent
Cube.Talk["Hey!"].Visible = false
script.Parent.Touched:Connect(function(Speak)
Cube.Awake.Transparency = 0
Cube.Asleep.Transparency = 1
Cube.Talk["Hey!"].Visible = true
task.wait(3)
Cube.Awake.Transparency = 1
Cube.Asleep.Transparency = 0
Cube.Talk["Hey!"].Visible = false
end)
This helped me.
heres the script i made.
local touchPart = game.Workspace.TouchPart
local partIsTouch = false
touchPart.Touched:Connect(function(otherPart)
if partIsTouch == false then
partIsTouch = true
print("Part is touched")
print(otherPart.Name)
touchPart.Material = Enum.Material.Neon
touchPart.BrickColor = BrickColor.Random()
task.wait(2)
partIsTouch = false
touchPart.Material = Enum.Material.Plastic
touchPart.BrickColor = BrickColor.new("Medium stone grey")
print("The part is back to normal!")
end
end)
i was here (maybe a future pro scripter)
But how can I make the color get back? i didnt get it sadly
are you still stuck? if yes, i can help
I was wondering if I could get another explanation of how the event using a function’s parameter works
Yessir:
local TouchPart1 = game.Workspace.TouchPart
local Colour = "White"
TouchPart1.Touched:Connect(function(OtherPart)
if Colour == "White" then
TouchPart1.BrickColor = BrickColor.new("Dark red")
task.wait(1)
TouchPart1.BrickColor = BrickColor.new("Sand green")
task.wait(1)
TouchPart1.BrickColor = BrickColor.new("Earth green")
task.wait(1)
TouchPart1.BrickColor = BrickColor.new("Hot pink")
task.wait(1)
TouchPart1.BrickColor = BrickColor.new("Electric blue")
task.wait(1)
task.wait(4)
print("cooldown done!")
Colour = "White"
end
end)
what kind of code"block" are "otherPart" and "player"? when i hover over them with the mouse, nothing shows up. pls help
local touch = game.Workspace.touch
local touched = false
touch.Touched:Connect(function(otherPart)
if not touched then
touched = true
print(otherPart.Name)
-- Change color to a random color every time it's touched
touch.Color = BrickColor.Random().Color
-- Reset touched flag after a short delay
task.wait(1)
touched = false
end
end)
local touchPart = game.Workspace.Touchpart
local partistouched = false
touchPart.Touched:connect(function(otherpart)
if partistouched == false then
partistouched = true
print("you have touched it")
task.wait("10")
partistouched = false
end
end)
to change the colour of a part randomly when you touch it with a cooldown of 2 seconds:
local Part = game.Workspace.Part
local sphereTouched = false
Part.Touched:Connect(function(thePart)
if sphereTouched == false then
sphereTouched = true
Part.BrickColor = BrickColor.Random()
task.wait(2)
sphereTouched = false
end
end)
local touch = game.Workspace.Part
local touchingpart = false
touch.Touched:Connect(function(otherpart)
if touchingpart == false then
touchingpart = true
touch.Transparency = 0.9
end
wait(1)
touch.Transparency = 0
touchingpart = false
end)
This script is pretty cool cuz whenever i touch the part it makes it almost dissapear for 2 secs try it out :)
i basically made an code that turns the part invisible and untouchable/uncollideable, and then after 5 seconds it turns visible again and touchable/collideable, and it doesnt turn invisible instantly, its bit by bit
local touchPart = game.Workspace.TouchPart
touchPart.Anchored = true
touchPart.CanTouch = true
touchPart.CanCollide = true
touchPart.BrickColor = BrickColor.Red()
touchPart.Transparency = 0
touchPart.Touched:Connect(function(otherPart)
touchPart.CanTouch = false
for i = 0, 10, 1 do
touchPart.Transparency = i/10
task.wait(0.1)
if i == 10 then
touchPart.CanCollide = false
task.wait(5)
touchPart.Transparency = 0
touchPart.CanCollide = true
touchPart.CanTouch = true
end
end
end)