How do you spawn a part with a pre-made script inside it?
i'm starting to practice scripting and one of the first tasks i've set myself is to make a setup where you press a button, a part spawns above your head and when it hits you it makes a bonk sound (comedy i know)
01 | local clickDetector = workspace.button 2. ClickDetector |
03 | clickDetector.MouseClick:connect( function (Player) |
05 | local Part = Instance.new( "Part" ) |
07 | local Script = Instance.new( "Script" , Part) |
09 | Part.Size = Vector 3. new( 4 , 1 , 2 ) |
11 | Part.Position = Player.Character:GetModelCFrame().Position + Vector 3. new( 0 , 5 , 0 ) |
13 | Part.Parent = workspace.Parts |
in line 7 there you can see i figured out how to put a blank script inside the part, but how would i put a script with code into the part?
the code is just the check for humanoid then sound play, that part works
thanks