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

How to get a value from from 2 model ?

Asked by 6 years ago

I'm trying to get a the value of a intvalue from a part from 2 model so what i tried i

local E = game.Workspace.House --There 2 Model Called "House" but i don't want to rename them

local F = E:FindFirstChild("House Pass")

if F then 
print("Openned")
else
print("Acces Denied")
0
is this like a key card to open a door tacobell158 10 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

There are a few problems with your script. I will address them as we move through this post.

If you don't want to rename one of the models called "House", you can simply use a table. You would use a table like so:

local Table = {}

Now, we need to address the houses. To do this we would use a loop. This loop will run through the workspace to search for any object named "House":

local Table = {}

for i,v in pairs(workspace:GetChildren()) do
    if v.Name == "House" then
        table.insert(Table, v) -- This would insert the model into the table previously created.
    end
end

Now that we have each house in the table, we would need to create another loop to search everything in the table for a "House Pass" integer value. You would do so like this:

local Table = {}

for i,v in pairs(workspace:GetChildren()) do
    if v.Name == "House" then
        table.insert(Table, v) -- This would insert the model into the table previously created.
    end
end

for i,v in pairs(Table) do
    if v:IsA("Model") then -- Making sure that the object being looped through is a model.
        if v:FindFirstChild("House Pass") and v:FindFirstChild("House Pass"):IsA("IntValue") then -- searching for the house pass integer.
            print("Opened "..v.Name)
        else
            print("Access denied from "..v.Name)
        end
    end
end

Hopefully this helped.

0
Thanks xJathur95x 129 — 6y
Ad

Answer this question