I want to make a script in which whenever a player touches the script, another part goes right next to the part holding the script. The only problem is, I want this to happen to the same part but in different spaces. This is my code so far
local Part = script.parent
function Touch()
Instance.new(Part, workspace) ----I have no clue on how to do what I stated above
end
Part.Touched:Connect(Touch)
local Part = script.parent
function Touch()
local part = Instance.new("Part")
part.Position = Vector3.new(0,0,0) -- put ur location here
part.Parent = workspace
end
Part.Touched:Connect(Touch)
It’s what @Katrist told you above but replace 0, 0, 0 with your x, y, z coordinates(you can find the x, y, z for a specific object in it’s Object.Position property).
What if i wanted to re-use the script? If i made the part go to the left side of a part and i moved where that part was, would it still go to the left side? or would it just go to the coordinates i added for it.
Depends on which way you consider left. If we assume the X axis is our left/right then you can do:
local Part = script.parent
local offset = 5
function Touch()
local part = Instance.new("Part")
part.Position = Vector3.new(part.Position.X-offset,0,0) -- put ur location here
part.Parent = workspace
end
Part.Touched:Connect(Touch)
local part = script.Parent
local debounce = false
part.Touched:Connect(function(hit)
if debounce then
return
end
if hit.Parent:FindFirstChild("Humanoid") then
debounce = true
local clone = part:Clone()
clone.Parent = workspace
clone.Position = part.Position + Vector3.new(4, 0, 0)
task.wait(3)
debounce = false
end
end)
This will create part instances in a line when the player touches the part.
You can also make it so that touched parts no longer create new parts by using the following.
local part = script.Parent
local isTouched = false
part.Touched:Connect(function(hit)
if isTouched then
return
end
if hit.Parent:FindFirstChild("Humanoid") then
isTouched = true
local clone = part:Clone()
clone.Parent = workspace
clone.Position = part.Position + Vector3.new(4, 0, 0)
task.wait(3)
end
end)