Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Mouse Target Filter issue?

Asked by 8 years ago

I know what does (mouse.Hit.p) do and i know what (mouse.TargetFilter) do, but what i want to know here is that there are 2 models, I want to ignore the descendant of both models. But sadly so far i only know how to ignore 1. Is there a way i can ignore both models?

Ps: mouse.TargetFilter = {Model1, Model2} doesnt work

2 answers

Log in to vote
1
Answered by
guges 15
8 years ago

It takes a model, not a table.

local function addToNewModel(bin, ...)
    local model = Instance.new("Model", bin)
    for _, v in pairs({...}) do
        v.Parent = model
    end
    return model
end

This function will take a place to put the new model (like workspace) and then put all of the arguments afterwards you give it in a new model, before returning this new model.

For example

addToNewModel(workspace, workspace.m1, workspace.m2)

Would take the models m1 and m2 and put them in a new model inside of workspace. This way you can just put all the models you want to ignore into this function and get a model.

0
Thanks very much, i have thought of that, but 1 problem is, 1 Model is in workspace, and 1 Model is in player's Camera. So.... FlaminSparrow 65 — 8y
0
Well in that case I'm not sure what you could do. If you're using localparts via the camera then I recommend trying to make the switch to FE. It helps things like this massively. guges 15 — 8y
Ad
Log in to vote
0
Answered by 6 years ago

I'm having a similar problem, although I technically could model the things together, I don't want to, because that could cause me issues later in developing. My answer is pretty similar to guges' answer, and so, building off of his code:

local function addToNewModel(bin, models)
    local model = Instance.new("Model", bin)
    previousPaths = {}
    for modelId, v in pairs(models) do
        previousPaths[modelId] = {v.Parent,v.Name}
        v.Name = tostring(modelId)
        v.Parent = model
    end
    return model, previousPaths
end

local function returnToPaths(bin, previousPaths)
    for _, v in pairs (bin:GetChildren()) do
        modelId = tonumber(v.Name)
        v.Parent = previousPaths[modelId][1]
        v.Name = previousPaths[modelId][2]
    end
end

(Please note, I haven't actually tested this, as I write, so there may be errors, but hopefully, you get the idea!)

And example usage would be as follows:

local function FilteredTarget(bin, filterTable, mouse)
    local model, previousPaths = addToNewModel(bin, filterTable)
    mouse.TargetFilter = model
    target = mouse.Target
    returnToPaths(bin, previousPaths)
    return target
end

I hope this helps (or at least that it might help inform an answer, even if I've messed up the code badly!)

Answer this question