Im in Roblox API looking at how to make a event fire when a player touches something, but it gives no example or syntax really. I dont want to just copy paste this to do what i want if it aint gonna work. Here is the website im looking at
http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Touched
How would i use this?
here is the box script
01 | local Character = game.Players.LocalPlayer |
02 | local part = script.Parent |
03 | _G.DieNibba = function () |
04 | part:Destroy() |
05 | end |
06 | repeat wait() until _G.giveXP |
07 |
08 |
09 | part.Touched:connect( function (hit) |
10 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
11 |
12 | game.Workspace.part:Destroy() |
13 |
14 | end |
15 | end ) |
just create a script, and put here what you want happen when you touch the part, put the script between function OnTouched(Part) and script.Parent.Touched:connect(OnTouched)
1 | function OnTouched(Part) |
2 |
3 |
4 | end |
5 |
6 | script.Parent.Touched:connect(OnTouched) |
It's easy just use a touched event. Let's say I insert a Part in the workspace called.. "Part54". You can insert a script ANYWHERE in the game you want and just say:
1 | game.Workspace.Part 54. Touched:connect( function (hit) |
2 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
3 | game.Workspace. [ YourPartName/In this case Part 54 ] :Destroy() |
4 | end |
5 | end ) |
It's that easy, just identify the object in the workspace and add .Touched! I hope this helps bro! :D
EDIT:You can just put that script inside the box/Part you want. And then put the following script. What it will do is:
Line1:If that part gets touched... Line2:If the "Thing" that touched is Human/Player then... Line3:Destroy the part! Line4:End the function at line 2 Line5:End the function at line 1
game.Players.LocalPlayer.Character.Touched:Connect(function() print('hi') end)