Hello, I am trying to make a script which finds a number of how many models are touching a part. The model is NPC and it has same name as other NPCS there is ussualy alot of them. Here is a script that dosen't really work it gives me only an amount of parts touching but not how many models touching.
local part = script.Parent local TopLeftFrontOfPart = part.Position - (0.5 * part.Size) local TopRightBackOfPart = part.Position + (0.5 * part.Size) local region = Region3.new(TopLeftFrontOfPart,TopRightBackOfPart) local count = 0 script.Parent.Touched:Connect(function() for _,Part in pairs(game.Workspace:FindPartsInRegion3(region,nil,math.huge)) do if Part.Parent.Name == "Dummy" then count = count + 1 end end print(count) count = 0 end)
Thanks.
Try this
if Part.Parent:IsA("Model") then local model = Part.Parent end
Maybe try this. Basically, I just made a table and inserted models into it.
local part = script.Parent local TopLeftFrontOfPart = part.Position - (0.5 * part.Size) local TopRightBackOfPart = part.Position + (0.5 * part.Size) local region = Region3.new(TopLeftFrontOfPart,TopRightBackOfPart) local count = 0 local models = {} script.Parent.Touched:Connect(function() for _,Part in pairs(game.Workspace:FindPartsInRegion3(region,nil,math.huge)) do if Part.Parent:IsA('Model') then if models[Part.Parent] then return else table.insert(models, Part.Parent) end end end count = (#models) print(count) table.clear(models) count = 0 end)
hey you! have you ever heard of enes? if you are in trouble, better call enes!