Question: How could I make it so if a player touches the part, it gives them a sword, and when they step off the part, it removes the sword from their inventory. Thanks!
Every step beautifully explained. Even when you explain something really well, you then explain it even further so that the audience completely understands. Outstanding. Thank you.
EXCELLENT TUTORIAL... I see so many young people rushing through tutorials and making errors mid video... this is perfect. If you're not a teacher , you should be because you're a natural. Very clear and well explained, also.
@TheDogCaused911 the best advice i could give you without seeing your script would be to check the syntax. Code is case sensative and must be precise. After that use prints to test points of your code instead of actions if you have acrid that are not triggering. Part.Touched:connect(function() print ("Part Touched") end)
Thanks for this video,the wiki didn't really explain it like it did for Functions. And holy shit,visual representations too? Lifesaver. Thanks so much for explaining the lines of code,and not just telling me "this will do that",I want to know what it does and how it works. Thanks again,you deserve my sub and like :D
OMG THANK YOU SO MUCH!!! Im a new dev and i was making a game, but had trouble when the death counter went up by multiple numbers when we touched the brick...i added the debounce and now it works...Thanks a lot!! U earned a sub, like and multiple shares
this is what I like about scripting, the possibility are endless and there are so many ways to mess around like when you touch a part, your head gets bigger or smaller
I appreciate the feedback. Hopefully it does get more popular! Do you have any specific questions? I could make some videos to cover anything you don't understand so others can learn as well.
@@CyberCreator ive got a question, how do you make a script play when you are in a certain area? In my game there is a tunnel and i have a disco script that I want to play ONLY inside the tunnel
Helpful vid! But I want to make a game where when you stand on a brick a dialog from an npc starts and you can ask questions by clicking on buttons, how would you do that?
If you are using a LocalScript, you can just type game.Players.LocalPlayer. If you are using a Script, you would need to work your way up to the Player. So if the Structure is Player->PlayerGui->ScreenGui->TextButton->Script You could get the player with script.Parent.Parent.Parent.Parent because the Player is the 4th Parent of the script.
Yeah heres some code to use: local part = script.Parent -- the variable of that part u touch local destroyBrick = game.Workspace.destroyman -- change "Destroyman" to the parts name. local function remove(player) destroyBirck:Destroy()-- destroys the other brick end part.Touched:Connect(remove) -- making it do the block of code above when you touch the part.
@@biack1st hey do you know how to make it like a riddle on it for instance if you find part 1 part 2 is now visible and part 1 is destroyed by any chance?
Yo!! Nice Vid, but may I get some help? I need it where if someone touches a brick it triggers a local script. ( I am trying to make it where if you touch a brick it triggers this local script which makes it if you press a key it will animate) Please help, if you can I need it ASAP for my game!
Yes! Use the code shown in the video to make to check if a player touched a part, and then if so make the Gui visible by toggling the "Enabled" property of the ScreenGui from false to true. You will want to use a debounce if you are copying the ScreenGui to the player's PlayerGui
i didn't watch the whole thing but, If this doesn't have a feature that can detect if your left arm or right arm touches a player after clicking e or r or something could you make a tutorial on it?
Hello CyberCreator I have a question, if I wanted to change something about the part that was actually hit with a touched event, or do something only if that part has a specific property (like material), how could I access that part? Oh and also the reason I can’t just put a script in the part and use script.parent is that I’m using a loop to connect the event to multiple parts as opposed to putting scripts in every single part
This is a really good question. The solution is to wrap the function that you are connected to with another function. At the time of looping through and connecting a function to the part, you have access to the part. This means you can just provide the part itself as a parameter to the function. I have an example below. Please keep in mind that the model could be wherever in this case. Let me know if you have questions local model = script.Parent local function doSomething(brick) print(brick.Name .. " was hit") end for _, part in ipairs(model:GetChildren()) do if part:IsA("Part") then part.Touched:Connect(function() doSomething(part) end) end end
@@CyberCreator wow thanks, I think I get it, I need access to both the part and the other part, but I can just pass them both into the inner function right?
script.Parent.Touched:Connect(function(hit) local explosion = Instance.new("Explosion") explosion.Position = hit.Position explosion.Parent = hit end) Put this in a script in a part
Hello, I was trying to find out how to do this, but with changing the material instead of color.. I tried changing the words color here to material, but that did not work. Could you please make a tutorial?!
I have a question: if this script is wrong or correct: Local Mypart = game.workspace.part Function Test() Print ("Its Worked") end script.parent.Mypart.Touched:Connect(Test) I don't know if the reference here is wrong. can answer please?
That is correct for the most part. You should note that capitalization is important. I've corrected your code below. I corrected the capitilization and the last line. I also added the local keyword in front of Test(). While this wasn't necessary, it is recommended. I have a video on local if you want to check it out. local Mypart = game.workspace.Part local function Test() print ("Its Worked") end Mypart.Touched:Connect(Test) Mypart acts as shorthand for "game.workspace.Part " so you could alternatively type game.workspace.Part .Touched:Connect(Test) for the last line. This is because you are making Mypart store a reference to the part in workspace.
local brick = script.Parent local function changeColor(otherPart) if otherPart.Parent:FindFirstChildWichIsA("Humanoid") then brick.BrickColor = BrickColor.Random() end end brick.Touched:Connect(changeColor) THat my code and this is my error FindFirstChildWichIsA is not a valid member of Workspace "Workspace" whats wrong
Hi i really want a collecting sytem if i step on a part its open a gui and every time i reach 10 coin = 1 rebirth it appear in the gui which can i collect can you show me how to do that its important for me :(
I am using a touch event to change the camera's position. However, when a player activates the touch event, the camera changes for all the players in game. I want it to change for the player that activates the touch event. Any help?
You could use a RemoteEvent and listen to the OnClientEvent method on the client. The server will use the FireClient function when a player has touched the part. Server code located within part: local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local camEvent = ReplicatedStorage:WaitForChild("CamChange") script.Parent.Touched:Connect(function(otherPart) if otherPart.Parent:FindFirstChildWhichIsA("Humanoid") then local player = Players:GetPlayerFromCharacter(otherPart.Parent) camEvent:FireClient(player) end end) Client code located in StarterPlayerScripts local ReplicatedStorage = game:GetService("ReplicatedStorage") local camEvent = ReplicatedStorage:WaitForChild("CamChange") local function changeCam() --Make whatever camera changes here workspace.CurrentCamera.FieldOfView = 100 end camEvent.OnClientEvent:Connect(changeCam) As you can see, I placed the RemoteEvent named "CamChange within ReplicatedStorage. I hope this helped. Don't forget to like the video, subscribe for more, and join the Discord: discord.gg/Mtf4KNY
I'm using this for when you touch a coin the coin disappeares only for the player that touched it can you plz try to do a thing where you make the script and tell me where to put the remote events, much appreciated
Join the discord and I can help more. You could keep a copy of the NPC in ReplicatedStorage, clone the NPC when a player touches the part, set the NPC's CFrame to the player's CFrame / wherever you want it to appear, and then Parent the clone to workspace. You can then add the clone to the Debris service and it will automatically be deleted after whatever time you set
How do you make when you a tool and it has a part called touch and when you touch another part (not in tool) thats named puck it stick and when you left click the part (puck) shoots
You can check to see if the parts name is equal to puck. So if the variable "part" is what touched your tool, you would check if part.Name == "Puck" then do whatever you want to execute under that condition. My video on operators explains how the == works, and my video on conditional statements explains the if then statement. As far as the left click detection, you should use UserInputService and check for MouseButton1 input. developer.roblox.com/en-us/api-reference/class/UserInputService Be sure to join the Discord for more questions! discord.gg/vrHQCMM
@@vitezlucello Sorry I didn't see this comment earlier. Yes you could check if the part has hit another part and then play a sound or make a gui pop up. Once the hit is detected, you could check if you've hit a part with the IsA function
I’m trying to create a function that tells me something touched the part and what the location of that part is in coordinates. how would I do that. I’m not sure how to access the players info.
Do you mean you're trying to get position of a player that touched the part?If so then you need to first check to see if it was a player that touched the part. If the parameter name you use for the part that touched the brick that is listening for the Touched event is called "partThatTouchedBrick", then you can check this with the conditional statement "if partThatTouchedBrick.Parent:FindFirstChild("Humanoid") then" If it was a player, then you can get the position of the player's root part "local characterPosition = partThatTouchedBrick.Parent.HumanoidRootPart.Position" Does that make sense?
@@CyberCreator yes that makes sense but what if it’s not a player but is like a missile or a plane. I’m trying to script a radarstation that detects whatever hits the radar wave and gives me it cords so I can then send that target info to a gun or missile.
excuse me CyberCreator, would you know how to make it so instead of the humanoid making everything react, how do i make it when an object (for instance, im making a soccer game and im looking for a touch event related to my goals and the soccer ball) touches another object and it reacts? im trying to make it so when my soccer ball touches the back of the net it reacts by saying goal. thankyou
Why do you use FindFirsrChildWhichIsA and not FindFirstChild? I did some research and the one you used is to find somethings class. Does that mean your explanation is incorrect?
No you don't need to use local scripts to do that. local DB = true -- Cooldown Local part = game.Workspace.INSERTNAME -- replace INSERTNAME with your parts name part.Touched:Connect(function(hit) --"hit" Defines what touched it If hit.Parent:FindFirstChild("Humanoid") and DB == true then -- Will only look for things with humanoid in it (Usually players) DB = false local tool = Tool -- replace with where ever your tool is stored local Cloned = tool:Cloned() Cloned.Parent = hit.Parent -- Puts Tool inside player making them equip it Wait(5) -- Edit how long you want players to wait to get another Tool DB = true end end) I only wrote this with barely any time to check and see if it works, I hope this helps!
Yes, but it has to be in the correct location. A LocalScript will only run Lua code if it is a descendant of one of the following objects: A Player’s Backpack, such as a child of a Tool A Player’s character model A Player’s PlayerGui A Player’s PlayerScripts. The ReplicatedFirst service You can use a LocalScript, but the script has to be in one of those locations. I put this script in StarterPlayerScripts, and it works. It helps to understand when you need to use WaitForChild, and the Roblox Client-Server model, but it isn't completely necessary. local brick = workspace:WaitForChild("Part") brick.Touched:Connect(function(otherPart) print (otherPart.Name) end
hi so i have a throwable part that detects when it hits a humanoid but sometimes it just hits the humanoid and roles back what alternative to touch events can i use?
That's a good question. The touched event does sometimes not fire when it should. There are a few ways to improve the detection. One method would be to use raycasting to follow the path of the projectile and check to see if a player is in that path. Another method would be to use a Region3 in the range of where the projectile is and check to see if a part of a player is in the region. You can read about that here -> developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartsInRegion3. You could also see if increasing the size of your hitbox would work. By this I mean that you could weld a larger part to your projectile with CanCollide set to false and Transparency set to 1 and make this larger part responsible for listening for touch events. Raycasting would probably be your most accurate solution. What type of projectile is it and how does the projectile move? Also, thanks for watching!
@@CyberCreator my projectile is a ball that bounces and is just using physics and how would i keep moving the region? im new to region3 edit: nevermind making a different hitbox for checking touched events works thanks
local part1 = script.Parent -- or wherever part1 is local part2 = game.Workspace:WaitForChild("Part2") part1.Touched:Connect(function(otherPart) if otherPart.Parent:FindFirstChild("Humanoid") then part2.CanCollide = false end end)
You could do that in the same was as shown in the video. However, you would likely want to check to see if the part that was touched is named "Generator" or whatever you name your generator. This is assuming you are listening for the Touched event of the Battery part
Hey I'm trying to make like a riddles script but I want it to be that you have to go to the first location to activate then go to the second riddle and the third and so on do you know how to pls I need help...
Well I had an issue and didn't know how to fix it, so I copied the exact script you used and it still spits out the same error. It says "FindFirstChildWichIsA is not a valid member of Workspace "Workspace"" And if I walk over it, it displays one of my body parts (the one that touched it) instead of Workspace.
how do i make it so that, when the player touches the part, the body part that has touched the part gets deleted? i want to make like a eradication weapon in my game.
also if you can just type humanoid why do we use findfirstchild and if we are using findfirstchild why do we need to confirm it is a humanoid that what it's supposed to do?
Idk.. if Part.Touched:Connect(function() then Part.Anchored = False end I think that's how, if im wrong, then find out by urself (im bad at some scripts)
When the Touched event is triggered, copy whatever gear and make the Parent the players Backpack. You can get the Player with the GetPlayerFromCharacter function. Make sure you check to see if it was a player who touched the brick, if it was get the character, and then clone the tool and set the parent to the player's backpack. developer.roblox.com/en-us/api-reference/function/Players/GetPlayerFromCharacter
You can make the players see different things if you change something in a LocalScript. So you could check to see if the Touch is occurring by the LocalPlayer's character and do something just for that client
How would you make it if two players touched? Because i would like to make a script if one player is bigger then the other and when they touch it would kill the smaller player, i just dont know if there is a different code for players.
If this was inside a part, it would set the characterName variable to the player's name script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local characterName = hit.Parent.name end end)
How to make a script, when a part is touched, then an new part appears in workspace? But, it needed to be touched with an exact object to run the script
But how to make something like: Touched event fires when player touched a part. But if other player will touch it in exact same time(not just break script after first player) nothing will happen.
i ahve a problem on anther thing i rebirth can 30k cash then when i do anther event to open a egg the value gets lost bc it is on clint of the rebirth and idk how to do it in server cus its gui
hi, i've a question, could u make a video that makes a collectable brick with ontch script ?, because i wanna create a quest for collect items but i find only with "Clickdetector" ! :'( thx by advance,
I plan on making an inventory video which relates to that. if you already have a system that works with ClickDetectors, it should be fairly easy making it work with the Touched event. Join the discord if you're trying to convert it: discord.gg/vrHQCMM
If you have any questions or requests for future videos, let me know!
Yes I do could u make a video that makes a brick with health gets damaged when the npc enemy touches it.
@@darrenchong2054 That's really specific for a full video, but if you join my Discord I can help you work out how to do this. discord.gg/YWqUMzw
@@CyberCreator can u help me with a game problem I have?
How would I script it where when a vehicle touches an invisible box it can trigger the lights that I scripted to begin on my Drag Tree.
Question: How could I make it so if a player touches the part, it gives them a sword, and when they step off the part, it removes the sword from their inventory. Thanks!
Every step beautifully explained. Even when you explain something really well, you then explain it even further so that the audience completely understands. Outstanding. Thank you.
Thank you so much for explaining the syntax, that is by far the biggest reason i dont know how to make something work
Happy to help!
AY THIS IS THE BEST TUTORIAL SEEN SO MANY THIS IS THE FIRST THAT EXPLAINS WHAT EVERYTHING THING DOES AND HOW TO BUILD IT TYSM
Glad I could help! Thanks for watching!
EXCELLENT TUTORIAL... I see so many young people rushing through tutorials and making errors mid video... this is perfect. If you're not a teacher , you should be because you're a natural. Very clear and well explained, also.
@TheDogCaused911 the best advice i could give you without seeing your script would be to check the syntax. Code is case sensative and must be precise. After that use prints to test points of your code instead of actions if you have acrid that are not triggering.
Part.Touched:connect(function()
print ("Part Touched")
end)
Thanks for this video,the wiki didn't really explain it like it did for Functions.
And holy shit,visual representations too? Lifesaver. Thanks so much for explaining the lines of code,and not just telling me "this will do that",I want to know what it does and how it works. Thanks again,you deserve my sub and like :D
I'm glad the video helped you out, and I appreciate the sub, like, and comment!
OMG THANK YOU SO MUCH!!! Im a new dev and i was making a game, but had trouble when the death counter went up by multiple numbers when we touched the brick...i added the debounce and now it works...Thanks a lot!! U earned a sub, like and multiple shares
Sweet! Good job getting it to work!
TYSM, NO VIDEO HAS BEEN ABLE TO EXPLAIN IT AS GOOD AS YOU!!! YESSSSS!!!!
This video was super helpful to understand how this works! Thanks a lot! ✨
I watched you last month when you had 100 subs and now you have 2k subs congratulations
Thanks for the support!
awesome tutorial. actually explains everything needed so people wont go back to endless tutorial hell :)
Thanks alot. This will help alot for me making a railway game for making the signals
Such clear concise and informative videos. Please keep doing these. I can't wait to learn from the rest of these.
Finally someone that can explain something CORRECTLY. EZ SUBCRIBE
this is helping me, how you're explaining what everything does. thank you :thumbs_up: this was on my b-day too
I'm glad I could help! Happy belated birthday, and don't forget to subscribe so you don't miss out on future videos!
Explained very well high quality content, I definitely subscribed because I want to say I was here before 100 subscribers, when you have 100,000.
Thanks! I'll see how quickly I can make you right!
one of the best tutorials I have seen
this is what I like about scripting, the possibility are endless and there are so many ways to mess around like when you touch a part, your head gets bigger or smaller
I didnt know about the built in disconnect function! now thats really cool
Thank you so much for this video, I have learn lots I hope that you can make more tutorials in the future!
this was made on my birthday no wonder why this is so cool B)
Happy late birthday! lol
thanks man great tutorial!
Glad you liked it!
Thank you so much dude! I can now make a working monolith in my Solar System exploration game!
thanks really clear and well put together
thank you!!!! this was very helpfull :)
Glad it was helpful!
Will you remember me when you become famous? :)
💯
best tutorial so far
Thanks for watching!
Thank you for explaining everything step by step 🙏
Glad it was helpful!
bro thank you so much i finally understand because of u!!!
Thanks so much dude helped alot
Thank you, yo! I made a small script without copying an entire script :D
you are a saint
Thanks for watching!
This is so well understandable
Question: Why isn't this video popular? Also do you mind giving me a quick session to teach me a bit more on stuff.
I appreciate the feedback. Hopefully it does get more popular! Do you have any specific questions? I could make some videos to cover anything you don't understand so others can learn as well.
@@CyberCreator ive got a question, how do you make a script play when you are in a certain area? In my game there is a tunnel and i have a disco script that I want to play ONLY inside the tunnel
@@maxb.4933 Try using 'if' statements and positional tracking
Ive been trying figure out how to detect if otherpart is a humanoid, hopefully this video helps!
Helpful vid! But I want to make a game where when you stand on a brick a dialog from an npc starts and you can ask questions by clicking on buttons, how would you do that?
this is soo helpful thank you still good in 2022
What do i put instead of “humanoid” if I’m trying to do a specific part instead
sorry for another comment lol, but how do you find the player or character (whichever is easier) of a player that pressed a text button?
If you are using a LocalScript, you can just type game.Players.LocalPlayer. If you are using a Script, you would need to work your way up to the Player.
So if the Structure is Player->PlayerGui->ScreenGui->TextButton->Script
You could get the player with script.Parent.Parent.Parent.Parent because the Player is the 4th Parent of the script.
Hi Cyber I have a tutorial idea for you! You have a bow and there's a target and when you shoot at the target a block appears
Is there a way that I can walk over a part that destroys a different part once touched?
Yeah heres some code to use:
local part = script.Parent -- the variable of that part u touch
local destroyBrick = game.Workspace.destroyman -- change "Destroyman" to the parts name.
local function remove(player)
destroyBirck:Destroy()-- destroys the other brick
end
part.Touched:Connect(remove) -- making it do the block of code above when you touch the part.
@@biack1st hey do you know how to make it like a riddle on it for instance if you find part 1 part 2 is now visible and part 1 is destroyed by any chance?
Great video
How would I script it where when a vehicle touches an invisible box it can trigger the lights that I scripted to begin on my Drag Tree.
Join the discord and we can help discord.gg/vrHQCMM
touch event could be used in anywhere its insane
Im very laggy on roblox studio,
Fast or not the F5(run) is always laggy so i need a good teacher, anyways thank you for making this video
please help how to make it so that if you touched the block then it will change the sky
OMG THANK YOU SO MUCH
Yo!! Nice Vid, but may I get some help? I need it where if someone touches a brick it triggers a local script. ( I am trying to make it where if you touch a brick it triggers this local script which makes it if you press a key it will animate) Please help, if you can I need it ASAP for my game!
Join the discord and we can help you out! discord.gg/X3zdqHy
Thank you very much!
Thank you so much.
just wondering, is there a way where you can touch a part and a gui pops up to teleport somewhere
Yes! Use the code shown in the video to make to check if a player touched a part, and then if so make the Gui visible by toggling the "Enabled" property of the ScreenGui from false to true. You will want to use a debounce if you are copying the ScreenGui to the player's PlayerGui
i didn't watch the whole thing but, If this doesn't have a feature that can detect if your left arm or right arm touches a player after clicking e or r or something could you make a tutorial on it?
That sounds pretty specific. We can help you work up a solution if you join the discord discord.gg/X3zdqHy
Hello CyberCreator I have a question, if I wanted to change something about the part that was actually hit with a touched event, or do something only if that part has a specific property (like material), how could I access that part?
Oh and also the reason I can’t just put a script in the part and use script.parent is that I’m using a loop to connect the event to multiple parts as opposed to putting scripts in every single part
This is a really good question. The solution is to wrap the function that you are connected to with another function. At the time of looping through and connecting a function to the part, you have access to the part. This means you can just provide the part itself as a parameter to the function. I have an example below. Please keep in mind that the model could be wherever in this case. Let me know if you have questions
local model = script.Parent
local function doSomething(brick)
print(brick.Name .. " was hit")
end
for _, part in ipairs(model:GetChildren()) do
if part:IsA("Part") then
part.Touched:Connect(function()
doSomething(part)
end)
end
end
@@CyberCreator wow thanks, I think I get it, I need access to both the part and the other part, but I can just pass them both into the inner function right?
@@sparklyspartan1833 Yep that is correct
I wanted one of the part touch on an object and exploded can you do that?
I would be appreciate about it. 😊
script.Parent.Touched:Connect(function(hit)
local explosion = Instance.new("Explosion")
explosion.Position = hit.Position
explosion.Parent = hit
end)
Put this in a script in a part
Hello, I was trying to find out how to do this, but with changing the material instead of color.. I tried changing the words color here to material, but that did not work. Could you please make a tutorial?!
I have a question: if this script is wrong or correct:
Local Mypart = game.workspace.part
Function Test()
Print ("Its Worked")
end
script.parent.Mypart.Touched:Connect(Test)
I don't know if the reference here is wrong. can answer please?
That is correct for the most part. You should note that capitalization is important. I've corrected your code below. I corrected the capitilization and the last line. I also added the local keyword in front of Test(). While this wasn't necessary, it is recommended. I have a video on local if you want to check it out.
local Mypart = game.workspace.Part
local function Test()
print ("Its Worked")
end
Mypart.Touched:Connect(Test)
Mypart acts as shorthand for "game.workspace.Part
" so you could alternatively type
game.workspace.Part
.Touched:Connect(Test)
for the last line. This is because you are making Mypart store a reference to the part in workspace.
@@CyberCreator Thanks, helped alot!
local brick = script.Parent
local function changeColor(otherPart)
if otherPart.Parent:FindFirstChildWichIsA("Humanoid") then
brick.BrickColor = BrickColor.Random()
end
end
brick.Touched:Connect(changeColor)
THat my code and this is my error
FindFirstChildWichIsA is not a valid member of Workspace "Workspace"
whats wrong
You spell Which wrong mg
You also need to place the script in a part
Hi i really want a collecting sytem if i step on a part its open a gui and every time i reach 10 coin = 1 rebirth it appear in the gui which can i collect can you show me how to do that its important for me :(
I am using a touch event to change the camera's position. However, when a player activates the touch event, the camera changes for all the players in game. I want it to change for the player that activates the touch event. Any help?
You could use a RemoteEvent and listen to the OnClientEvent method on the client. The server will use the FireClient function when a player has touched the part.
Server code located within part:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camEvent = ReplicatedStorage:WaitForChild("CamChange")
script.Parent.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChildWhichIsA("Humanoid") then
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
camEvent:FireClient(player)
end
end)
Client code located in StarterPlayerScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camEvent = ReplicatedStorage:WaitForChild("CamChange")
local function changeCam()
--Make whatever camera changes here
workspace.CurrentCamera.FieldOfView = 100
end
camEvent.OnClientEvent:Connect(changeCam)
As you can see, I placed the RemoteEvent named "CamChange within ReplicatedStorage. I hope this helped. Don't forget to like the video, subscribe for more, and join the Discord: discord.gg/Mtf4KNY
@@CyberCreator Oh alright! Thanks a ton!
I'm using this for when you touch a coin the coin disappeares only for the player that touched it can you plz try to do a thing where you make the script and tell me where to put the remote events, much appreciated
Hey sir how to make a jumpscare for horror game like When part touched an npc will appear and disappear for 3 seconds or more
Join the discord and I can help more. You could keep a copy of the NPC in ReplicatedStorage, clone the NPC when a player touches the part, set the NPC's CFrame to the player's CFrame / wherever you want it to appear, and then Parent the clone to workspace. You can then add the clone to the Debris service and it will automatically be deleted after whatever time you set
How do you make when you a tool and it has a part called touch and when you touch another part (not in tool) thats named puck it stick and when you left click the part (puck) shoots
You can check to see if the parts name is equal to puck. So if the variable "part" is what touched your tool, you would check if part.Name == "Puck" then do whatever you want to execute under that condition. My video on operators explains how the == works, and my video on conditional statements explains the if then statement. As far as the left click detection, you should use UserInputService and check for MouseButton1 input. developer.roblox.com/en-us/api-reference/class/UserInputService
Be sure to join the Discord for more questions! discord.gg/vrHQCMM
@@CyberCreator Well I mean could you make if the puck (part) hits another part for example wall it plays a sound or gives a message to a gui
@@vitezlucello Sorry I didn't see this comment earlier. Yes you could check if the part has hit another part and then play a sound or make a gui pop up. Once the hit is detected, you could check if you've hit a part with the IsA function
I’m trying to create a function that tells me something touched the part and what the location of that part is in coordinates. how would I do that. I’m not sure how to access the players info.
Do you mean you're trying to get position of a player that touched the part?If so then you need to first check to see if it was a player that touched the part. If the parameter name you use for the part that touched the brick that is listening for the Touched event is called "partThatTouchedBrick", then you can check this with the conditional statement
"if partThatTouchedBrick.Parent:FindFirstChild("Humanoid") then"
If it was a player, then you can get the position of the player's root part
"local characterPosition = partThatTouchedBrick.Parent.HumanoidRootPart.Position"
Does that make sense?
@@CyberCreator yes that makes sense but what if it’s not a player but is like a missile or a plane. I’m trying to script a radarstation that detects whatever hits the radar wave and gives me it cords so I can then send that target info to a gun or missile.
excuse me CyberCreator, would you know how to make it so instead of the humanoid making everything react, how do i make it when an object (for instance, im making a soccer game and im looking for a touch event related to my goals and the soccer ball) touches another object and it reacts? im trying to make it so when my soccer ball touches the back of the net it reacts by saying goal. thankyou
uhh i think you just replace humanoid with the name of your hit box i think
thank you
Thanks for watching!
9:45 why isn't the first child bodycolors? (I just started to learned script a day ago)
Why do you use FindFirsrChildWhichIsA and not FindFirstChild? I did some research and the one you used is to find somethings class. Does that mean your explanation is incorrect?
for some reason the touched even is broken for me when ever i touch the part it just doesn't do anything and i tried putting a print and still nothing
Is there any way to make some trigger box without colliding
I'm not entirely sure what you mean? Maybe anchoring the part and turning CanCollide to false would work? Could you explain more?
can local scrips use touch events?
if not how to i have it so when someone touches a part it gives them a sword
No you don't need to use local scripts to do that.
local DB = true -- Cooldown
Local part = game.Workspace.INSERTNAME -- replace INSERTNAME with your parts name
part.Touched:Connect(function(hit) --"hit" Defines what touched it
If hit.Parent:FindFirstChild("Humanoid") and DB == true then -- Will only look for things with humanoid in it (Usually players)
DB = false
local tool = Tool -- replace with where ever your tool is stored
local Cloned = tool:Cloned()
Cloned.Parent = hit.Parent -- Puts Tool inside player making them equip it
Wait(5) -- Edit how long you want players to wait to get another Tool
DB = true
end
end)
I only wrote this with barely any time to check and see if it works, I hope this helps!
Yes, but it has to be in the correct location.
A LocalScript will only run Lua code if it is a descendant of one of the following objects:
A Player’s Backpack, such as a child of a Tool
A Player’s character model
A Player’s PlayerGui
A Player’s PlayerScripts.
The ReplicatedFirst service
You can use a LocalScript, but the script has to be in one of those locations.
I put this script in StarterPlayerScripts, and it works. It helps to understand when you need to use WaitForChild, and the Roblox Client-Server model, but it isn't completely necessary.
local brick = workspace:WaitForChild("Part")
brick.Touched:Connect(function(otherPart)
print (otherPart.Name)
end
thank you so much
How do I make it pop up a perches on screen but the perches is invisible
hi so i have a throwable part that detects when it hits a humanoid but sometimes it just hits the humanoid and roles back what alternative to touch events can i use?
That's a good question. The touched event does sometimes not fire when it should. There are a few ways to improve the detection. One method would be to use raycasting to follow the path of the projectile and check to see if a player is in that path. Another method would be to use a Region3 in the range of where the projectile is and check to see if a part of a player is in the region. You can read about that here -> developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartsInRegion3. You could also see if increasing the size of your hitbox would work. By this I mean that you could weld a larger part to your projectile with CanCollide set to false and Transparency set to 1 and make this larger part responsible for listening for touch events. Raycasting would probably be your most accurate solution. What type of projectile is it and how does the projectile move? Also, thanks for watching!
@@CyberCreator my projectile is a ball that bounces and is just using physics and how would i keep moving the region? im new to region3
edit: nevermind making a different hitbox for checking touched events works thanks
I’m glad to hear that worked out!
0:31
beacon boi : **I AM SPEEEEEDD**
lol
how to make a part that when you touch it it makes an other part can collide false
local part1 = script.Parent -- or wherever part1 is
local part2 = game.Workspace:WaitForChild("Part2")
part1.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") then
part2.CanCollide = false
end
end)
@@CyberCreator oh my god tysm
How do i make an event happen when a tool touch a part for example: a battery touches a generator
You could do that in the same was as shown in the video. However, you would likely want to check to see if the part that was touched is named "Generator" or whatever you name your generator. This is assuming you are listening for the Touched event of the Battery part
@@CyberCreator Thanks, helped a lot!
Hey I'm trying to make like a riddles script but I want it to be that you have to go to the first location to activate then go to the second riddle and the third and so on do you know how to pls I need help...
Found a bug in a script that plays a sound on client every time you touch but it was spamming the sounds like 3 of them if i touched the part, Thanks!
Well I had an issue and didn't know how to fix it, so I copied the exact script you used and it still spits out the same error.
It says "FindFirstChildWichIsA is not a valid member of Workspace "Workspace""
And if I walk over it, it displays one of my body parts (the one that touched it) instead of Workspace.
dont know if you fixed it but make sure you put a ":" instead of a "."
Bro i want to keep firing the touch event even when the player isnt moving. How do you do it?
ok wait but is there a way to make it so when a player touches a player they both die?
how do i make it so that, when the player touches the part, the body part that has touched the part gets deleted? i want to make like a eradication weapon in my game.
also if you can just type humanoid why do we use findfirstchild and if we are using findfirstchild why do we need to confirm it is a humanoid that what it's supposed to do?
how do you detect if another part is touching the part
How do I make it so when you touch a part it becomes unanchored?
Idk.. if Part.Touched:Connect(function() then
Part.Anchored = False
end
I think that's how, if im wrong, then find out by urself (im bad at some scripts)
would this work if the part is set to non-collide?
sir can you make a tutorial of how to make dialogue triggered by touch of a part
How do i make it when a player touches a brick it gives them a certain gear, or if thats possible
When the Touched event is triggered, copy whatever gear and make the Parent the players Backpack. You can get the Player with the GetPlayerFromCharacter function. Make sure you check to see if it was a player who touched the brick, if it was get the character, and then clone the tool and set the parent to the player's backpack. developer.roblox.com/en-us/api-reference/function/Players/GetPlayerFromCharacter
Is this for the client, I want the players to see different things
You can make the players see different things if you change something in a LocalScript. So you could check to see if the Touch is occurring by the LocalPlayer's character and do something just for that client
I was looking for when you touch a part it does a animation
I search for a vid actually that detect when part1 touched part2 it will do something without the Hunanoid
Is there a way to make the script fire when it comes in contact with another part?
hey please respond me, so how do i make an object animation like a car play when i touch a block please i need help
How would you make it if two players touched? Because i would like to make a script if one player is bigger then the other and when they touch it would kill the smaller player, i just dont know if there is a different code for players.
How would you script playing a sound when a player touches another player?
how would i detect a cloned part being touched when there are multiple coned parts?
how do you figure out the name of the player that touched it?
If this was inside a part, it would set the characterName variable to the player's name
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local characterName = hit.Parent.name
end
end)
@@CyberCreator ok thx!
How to make a script, when a part is touched, then an new part appears in workspace?
But, it needed to be touched with an exact object to run the script
But how to make something like:
Touched event fires when player touched a part. But if other player will touch it in exact same time(not just break script after first player) nothing will happen.
i ahve a problem on anther thing i rebirth can 30k cash then when i do anther event to open a egg the value gets lost bc it is on clint of the rebirth and idk how to do it in server cus its gui
hi, i've a question, could u make a video that makes a collectable brick with ontch script ?, because i wanna create a quest for collect items but i find only with "Clickdetector" ! :'(
thx by advance,
I plan on making an inventory video which relates to that. if you already have a system that works with ClickDetectors, it should be fairly easy making it work with the Touched event. Join the discord if you're trying to convert it: discord.gg/vrHQCMM