I am trying to make a script when a player touched a certain "part" it will clone then destroy but when I end the script it says I need to correct it.
SCRIPT:
if game.Players.Player1.Humanoid.onTouched then game.Workspace.Part:Clone end then wait(10) game.Workspace.Part:Remove() end
Touched
is an event, and it needs to be treated as such. Here's a quick rundown of how events work:
1 | function onTouched(hit) -- Events need a function (which will be run every time the event is fired) |
2 | local cloned = game.Workspace.Part:clone() -- clone() is a method. |
3 | cloned.Parent = game.Workspace -- Forgot this the first time. You need to give your new part a parent |
4 | wait( 10 ) -- Wait 10 seconds |
5 | game.Workspace.Part:Destroy() -- Destroy is better than remove |
6 | end |
7 |
8 | game.Players.Player 1. Torso.Touched:connect(onTouched) -- Connecting our function to the event. Note that this is for the player's torso, there is no Touched event for Humanoids. |
Different events pass different arguments. A great way to figure out which arguments are passed is on the ROBLOX Wiki. The page for the touched event is right here.
1 | game.Players.Player 1. Character.Torso.Touched:connect( function (hit) |
2 | local cloned = workspace.Part:clone() |
3 | cloned.Parent = workspace |
4 | game:GetService( "Debris" ):AddItem(cloned, 10 ) |
5 | end ) |