how do i make a script when u touch part1, a new part2 pops up using instance.new
COMMUNITY QUESTION
how do i make a script when u touch part1, a new part2 pops up using instance.new?
1 answer
How do i make a script when u touch part1, a new part2 pops up using instance.new?
To make a script that creates a new part when you touch another part, you can use the Touched event on the part that you want to touch, and the Instance.new function to create a new instance of the Part class. Here is an example of how you could do this:
-- Define the name and size of the part that will be created
local partName = "Part2"
local partSize = Vector3.new(2, 2, 2)
-- Define the part that you want to touch
local part1 = script.Parent
-- Bind a function to the Touched event on the part
part1.Touched:Connect(function(otherPart)
-- Check if the other part is a humanoid
if otherPart:IsA("Humanoid") then
-- Create a new part and set its properties
local part2 = Instance.new("Part")
part2.Name = partName
part2.Size = partSize
part2.Parent = workspace
end
end)
In this script, the Touched event is bound to a function that checks if the other part that was touched is a Humanoid. If it is, a new Part is created and added to the Workspace.
You can customize the script to change the name and size of the part that is created, as well as the part that you want to touch.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
This will never get past the if statement. 'otherPart' will never be the Humanoid, because the Humanoid is not a part...
When the character comes into contact with the given part, the returned part will be a body part of the character. The parent of that body part is the character model. From there you can check if the character has a Humanoid.