whats the best way to check if a model is being touched?
when i mean a model, it is a model with some parts in it
tried this but did not work
local function checkTouch(model)
for _, part in pairs(model:GetDescendants()) do
if part:IsA("BasePart") then
part.Touched:Connect(function(hit)
print("Touched")
local function checkTouch(model)
for _, part in pairs(model:GetDescendants()) do
if part:IsA("BasePart") then
part.Touched:Connect(function(hit)
print("Touched")
end)
end
end
end
This code should work, im assuming you didn’t add the ends on the end of the function. Considering it then moot without the ends in correct placement.
I get this, which in the first case is what I was going to do. However if the model is a complex shape the player may have wanted the bounding boxes to have had more precise locations. Therefore leaving me to just assume that the original code was what he intended, they just wanted to fix the errors within their original code. But nevertheless thanks for that suggestion too!
import ur roblox studio model to blender and then cut a cube in blender being the shape of the imported model then import the blender model to roblox and put it in ur roblox studio model and name it HITBOX and ur the script above this will ensure its all covered and gives it a very precise HITBOX
It isn’t, but it’s always better to avoid lag as much as you can.
Instead, use this code and put it in a Script in ServerScriptService.
local model = --locate ur model here
for i, v in pairs(model:GetChildren) do
if v:IsA("Part") then
v.Touched:Connect(function()
-- do whatever you want here, and it'll fire once one of the parts is touched.
end)
end
end
I wrote it on phone, so it might give you an error. If it did, tell me!