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

If I had a function which I needed a variable from for another function.. how would I do that?

function GetSpecificPlane()
	for _,v in pairs (workspace:GetChildren()) do
		if v:IsA("Model") then
			if v.Name == "PlaneTest" then
				if v.OwnedBy.Value == player.Name then
					print("Confirmed ownership, user in charge is "..player.Name.."!")
				else
					print("It appears we have a major bug captain. ABORTTT!!!")
				end
			end
		end
	end
end

function CFRAME()
	
	GetSpecificPlane()
	--How would I get 'v' from this function over to this one?
end

So here is my code. I am using the function GetSpecificPlane() to find a plane marked as the users plane. All that is fine. What I'm curious about is if there is any way I could add some sort of argument which can hold v in the GetSpecificPlane() function and use it in the CFRAME() function.

1 answer

✓ Accepted answer

It depends on what you want to do. I think that you want the function to return the plane the player owns, which can be done by returning a value, like this:

function GetSpecificPlane()
    for _,v in pairs (workspace:GetChildren()) do
        if v:IsA("Model") then
            if v.Name == "PlaneTest" then
                if v.OwnedBy.Value == player.Name then
                    print("Confirmed ownership, user in charge is "..player.Name.."!")
		    return v
                else
                    print("It appears we have a major bug captain. ABORTTT!!!")
                end
            end
        end
    end
end

function CFRAME()

    local plane = GetSpecificPlane()
    print(plane.Name)
    --How would I get 'v' from this function over to this one?
end

This might not be what you are looking for, in which case simply comment and I will edit. If it was you are looking for, please mark this answer.

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