Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to get a value from from 2 model ?

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")

1 comment

0

is this like a key card to open a door

1 answer

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.

1 comment

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.