I have been trying to work on learning on how to print the name of the part touched but I dont know why my script only register player parts and not non player parts I have attached the script and the video please help me
local pert = workspace.Part
pert.Touched:Connect(function(otherPart)
print(otherPart.Name)
end)
while true do
task.wait(0.3)
local os = pert.Size
pert.Size = pert.Size + Vector3.new(0, 1, 0)
local ns = pert.Size
local Offsety = (ns.Y - os.Y) / 2
pert.Position = pert.Position + Vector3.new(0, Offsety, 0)
end
This event only fires as a result of physical movement, so it will not fire if the CFrame property was changed such that the part overlaps another part. This also means that at least one of the parts involved must not be Anchored at the time of the collision.
Yes, but I would not use .Touched events for this, I’d make a custom function that suits your needs.
Code:
local part = workspace.Part
local alreadyTouched = {}
local function onTouched(otherPart)
print(otherPart.Name)
end
while true do
task.wait(0.3)
local oldSize = part.Size
part.Size += Vector3.new(0, 1, 0)
local offsetY = (part.Size.Y - oldSize.Y) / 2
part.Position += Vector3.new(0, offsetY, 0)
local touchingParts = workspace:GetPartsInPart(part)
for _, otherPart in touchingParts do
if not alreadyTouched[otherPart] then
alreadyTouched[otherPart] = true
onTouched(otherPart)
end
end
end
As the red block grows upward once it begins overlapping the white part workspace:GetPartsInPart(part) will detect the white part and you can print its name. Nothing needs to be unanchored. GetPartsInPart() checks which parts currently share space with the red block.
Thanks for the help but I am also trying to make the touched part unanchored but I don’t know why the part starts to fly though the print name works now
local part = workspace.Part
local alreadyTouched = {}
local function onTouched(otherPart)
print(otherPart.Name)
otherPart.Anchored = false
end
while true do
task.wait(0.3)
local oldSize = part.Size
part.Size += Vector3.new(0, 1, 0)
local offsetY = (part.Size.Y - oldSize.Y) / 2
part.Position += Vector3.new(0, offsetY, 0)
local touchingParts = workspace:GetPartsInPart(part)
for _, otherPart in touchingParts do
if not alreadyTouched[otherPart] then
alreadyTouched[otherPart] = true
onTouched(otherPart)
end
end
end
